Sha256: 382809f9f1610da0168ed5b7a27537c8b151423829d3fc381b34ff509a98dbf6

Contents?: true

Size: 1.13 KB

Versions: 2

Compression:

Stored size: 1.13 KB

Contents

# * George Moschovitis  <gm@navel.gr>
# (c) 2004-2005 Navel, all rights reserved.
# $Id: bench.rb 263 2005-02-23 13:45:08Z gmosx $

require 'og'; include Og


config = {
	:adapter => 'sqlite',
	:database => 'test',
	:connection_count => 5 
}

class Article
	prop_accessor :title, String
	prop_accessor :body, String
	prop_accessor :hits, Fixnum
	prop_accessor :rate, Fixnum

	def initialize(title = nil, body = nil)
		@title = title
		@body = body
		@hits = rand(5)
		@rate = rand(100)
	end
end

Database.drop_db!(config)
db = Database.new(config)

# Benchmark the insert speed. Useful for finding
# the improvement when using prepared statements.

articles = []

500.times do |i|
	articles << Article.new("Title#{i}", "Body#{i}")
end

sum = 0
min = 999999
max = -min

GC.disable

10.times do |i|

	db.exec "DELETE FROM #{Article::DBTABLE}"

	for article in articles
		article.oid = nil
	end

	Article.create("Dummy", "Dummy")
	
	t1 = Time.now
	articles.each do |a|
		a.save!
	end
	t2 = Time.now

	d = t2 - t1
	sum += d
	min = d if d < min
	max = d if d > max
	
	puts "Insert test #{i}: #{d} seconds"

end

puts %{
Min: #{min}
Max: #{max}
Average: #{sum/10}
}

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
nitro-0.11.0 benchmark/og/bench.rb
nitro-0.12.0 benchmark/og/bench.rb