Skip to content

Instantly share code, notes, and snippets.

@fearoffish
Created December 18, 2009 12:42
Show Gist options
  • Save fearoffish/259473 to your computer and use it in GitHub Desktop.
Save fearoffish/259473 to your computer and use it in GitHub Desktop.
require "rubygems"
require "mongo_mapper"
require 'benchmark'
count = 1000000
MongoMapper.connection = Mongo::Connection.new('localhost')
MongoMapper.database = 'benchmark'
class Person
include MongoMapper::Document
key :name, String
key :email, String
key :street, String
key :city, String
key :zip, String
end
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 8.890000 0.080000 8.970000 ( 8.996704)
# write 868.050000 34.060000 902.110000 (910.455185)
# read 450.220000 30.440000 480.660000 (560.226702)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment