Sha256: 69a6be041444d169022eea58aeeeb1dc48cba33162f50033241655cd2e0ffa8e

Contents?: true

Size: 1.17 KB

Versions: 7

Compression:

Stored size: 1.17 KB

Contents

# * George Moschovitis  <gm@navel.gr>
# (c) 2004-2005 Navel, all rights reserved.
# $Id: bench.rb 182 2005-07-22 10:07:50Z 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

7 entries across 7 versions & 1 rubygems

Version Path
og-0.21.0 benchmark/bench.rb
og-0.21.2 benchmark/bench.rb
og-0.22.0 benchmark/bench.rb
og-0.23.0 benchmark/bench.rb
og-0.24.0 benchmark/bench.rb
og-0.25.0 benchmark/bench.rb
og-0.26.0 benchmark/bench.rb