Skip to content

Instantly share code, notes, and snippets.

@shingara
Created January 11, 2010 22:08
Show Gist options
  • Save shingara/274654 to your computer and use it in GitHub Desktop.
Save shingara/274654 to your computer and use it in GitHub Desktop.
gem 'mongo_mapper'
require 'mongo_mapper'
MongoMapper.database = 'benchmarking'
class Foo
include MongoMapper::Document
key :approved, Boolean
key :count, Integer
key :approved_at, Time
key :expire_on, Date
timestamps!
end
Foo.collection.remove
gem 'mongoid'
require 'mongoid'
connection = Mongo::Connection.new('localhost')
Mongoid.database = connection.db('benchmarking')
class Bar
include Mongoid::Document
include Mongoid::Timestamps
field :approved, :type => Boolean
field :count, :type => Integer
field :approved_at, :type => Time
field :expire_on, :type => Date
end
Bar.collection.remove
Benchmark.bm(5) do |x|
puts('MongoMapper')
ids = []
x.report("write") do
1000.times { |i| ids << Foo.create(:count => 0, :approved => true, :approved_at => Time.now, :expire_on => Date.today).id }
end
x.report("read ") do
ids.each { |id| Foo.first(:id => id) }
end
x.report("all ") do
(ids.size / 10).times do |t|
Foo.all(:approved => true, :page => t, :per_page => 10).each do |f|
f.id
end
end
end
end
Benchmark.bm(5) do |x|
puts 'MongoId'
ids = []
x.report("write") do
1000.times { |i| ids << Bar.create(:count => 0, :approved => true, :approved_at => Time.now, :expire_on => Date.today).id }
end
x.report("read ") do
ids.each { |id| Bar.find(:first, :conditions => {:id => id}) }
end
x.report("all ") do
(ids.size / 10).times do |t|
Bar.paginate(:conditions => {:approved => true, :page => t, :per_page => 10}).each do |f|
f.id
end
end
end
end
user system total real
MongoMapper
write 1.310000 0.040000 1.350000 ( 1.367452)
read 0.790000 0.050000 0.840000 ( 0.949411)
all 0.120000 0.000000 0.120000 ( 0.261779)
user system total real
MongoId
write 1.560000 0.040000 1.600000 ( 1.606055)
read 0.430000 0.030000 0.460000 ( 1.391272)
all 0.080000 0.000000 0.080000 ( 0.376099)
user system total real
MongoMapper
write 4.130000 0.080000 4.210000 ( 4.323286)
read 2.190000 0.080000 2.270000 ( 2.545203)
all 0.050000 0.000000 0.050000 ( 0.176148)
user system total real
MongoId
write 1.630000 0.040000 1.670000 ( 1.712532)
read 0.520000 0.040000 0.560000 ( 4.288453)
all 0.170000 0.010000 0.180000 ( 0.697488)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment