Skip to content

Instantly share code, notes, and snippets.

@gaffneyc
Created July 6, 2011 19:27
Show Gist options
  • Save gaffneyc/1068114 to your computer and use it in GitHub Desktop.
Save gaffneyc/1068114 to your computer and use it in GitHub Desktop.
require 'rubygems'
require 'benchmark'
require 'mongo_mapper'
require 'mongoid'
# With GC enabled
# Rehearsal -----------------------------------------------------------
# mongomapper creates 0.350000 0.010000 0.360000 ( 0.374451)
# Mongoid creates 0.210000 0.000000 0.210000 ( 0.224762)
# Mongomapper reads 0.480000 0.020000 0.500000 ( 0.685909)
# Mongoid reads 0.230000 0.020000 0.250000 ( 0.427573)
# Mongomapper reads - all 46.170000 1.390000 47.560000 ( 48.424656)
# Mongoid reads 12.840000 1.250000 14.090000 ( 14.581846)
# ------------------------------------------------- total: 62.970000sec
#
# user system total real
# mongomapper creates 0.280000 0.000000 0.280000 ( 0.297822)
# Mongoid creates 0.150000 0.010000 0.160000 ( 0.152701)
# Mongomapper reads 0.370000 0.020000 0.390000 ( 0.584758)
# Mongoid reads 0.160000 0.010000 0.170000 ( 0.351070)
# Mongomapper reads - all 92.590000 2.740000 95.330000 ( 97.169594)
# Mongoid reads 25.600000 2.460000 28.060000 ( 28.976055)
MongoMapper.connection = Mongo::Connection.new
MongoMapper.database = "benchmarkitation"
Mongoid.configure do |config|
config.master = Mongo::Connection.new.db("benchmarkitation")
end
class MongoUser
include MongoMapper::Document
key :username, String
key :email, String
key :position, Integer
end
class MongoidUser
include Mongoid::Document
field :username, :type => String
field :email, :type => String
field :position, :type => Integer
end
n = 500
Benchmark.bmbm do |x|
data = {:username => "ian", :email => '[email protected]'}
MongoUser.collection.drop
x.report("mongomapper creates") {
n.times do |pos|
user = MongoUser.new(data)
user.position = pos
user.save!
end
}
MongoidUser.collection.drop
x.report("Mongoid creates") {
n.times do |pos|
user = MongoidUser.new(data)
user.position = pos
user.save
end
}
x.report("Mongomapper reads") {
n.times do |pos|
MongoUser.where(:position => pos).first.inspect
end
}
x.report("Mongoid reads") {
n.times do |pos|
MongoidUser.where(:position => pos).first.inspect
end
}
x.report("Mongomapper reads - all") {
n.times do
MongoUser.all.each(&:position)
end
}
x.report("Mongoid reads - all") {
n.times do
MongoidUser.all.each(&:position)
end
}
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment