Skip to content

Instantly share code, notes, and snippets.

@lsegal
Created November 27, 2009 02:54
Show Gist options
  • Save lsegal/243798 to your computer and use it in GitHub Desktop.
Save lsegal/243798 to your computer and use it in GitHub Desktop.
require 'benchmark'
require_relative '../lib/odb'
$db = ODB.new
class MyObj
attr_accessor :__serialize_key__
include ODB::Persistent
end
def create_objs
TIMES.times {|i| MyObj.new.tap {|o| o.__serialize_key__ = "obj#{i}".to_sym } }
end
TIMES = 100_000
Benchmark.bmbm do |x|
x.report("nonpersisted") { create_objs }
x.report("persisted ") { $db.transaction { create_objs } }
end
__END__
Rehearsal ------------------------------------------------
nonpersisted 0.340000 0.010000 0.350000 ( 0.359124)
persisted 0.290000 0.010000 0.300000 ( 0.290687)
--------------------------------------- total: 0.650000sec
user system total real
nonpersisted 0.250000 0.000000 0.250000 ( 0.246094)
persisted 0.280000 0.000000 0.280000 ( 0.289827)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment