Skip to content

Instantly share code, notes, and snippets.

@fearoffish
Created December 18, 2009 13:53
Show Gist options
  • Save fearoffish/259500 to your computer and use it in GitHub Desktop.
Save fearoffish/259500 to your computer and use it in GitHub Desktop.
require "rubygems"
require "benchmark"
require "dm-core"
count = 1000000
class Person
include DataMapper::Resource
property :id, Serial
property :name, String
property :email, String
property :street, String
property :city, String
property :zip, String
end
DataMapper.setup(:default, "mysql://root@localhost/benchmark")
DataMapper.auto_migrate!
Benchmark.bm(10) do |x|
x.report("base") do
count.to_i.times do |i|
object = {
:name => "bob#{i}",
:email => "bob#{i}@bob.com",
:street => "street#{i}",
:city => "city#{i}",
:zip => "#{rand(i)}"
}
# r[i] = object
end
end
x.report("write") do
count.to_i.times do |i|
object = {
:name => "bob#{i}",
:email => "bob#{i}@bob.com",
:street => "street#{i}",
:city => "city#{i}",
:zip => "#{rand(i)}"
}
person = Person.create(object)
end
end
x.report("read") do
count.to_i.times do |i|
Person.find(i)
end
end
end
# user system total real
# base 10.920000 0.110000 11.030000 ( 11.051787)
# write 698.140000 51.100000 749.240000 (2080.655682)
# read 910.590000 35.280000 945.870000 (1053.984296)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment