Created
July 6, 2011 17:34
-
-
Save seeingidog/1067821 to your computer and use it in GitHub Desktop.
redis ORMs/mongo ORM benchmarks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'benchmark' | |
require 'ohm' | |
require 'datamapper' | |
require 'dm-redis-adapter' | |
require "redis" | |
require 'json' | |
require 'mongo_mapper' | |
MongoMapper.connection = Mongo::Connection.new | |
MongoMapper.database = "testings" | |
redis = Redis.new | |
Ohm.connect | |
DataMapper.setup(:default, {:adapter => "redis"}) | |
class MongoUser | |
include MongoMapper::Document | |
key :username, String | |
key :email, Integer | |
end | |
class DMUser | |
include DataMapper::Resource | |
property :id, Serial | |
property :username, String | |
property :email, String | |
end | |
class OhmUser < Ohm::Model | |
attribute :username | |
attribute :email | |
end | |
n = 500 | |
Benchmark.bm do |x| | |
data = {:username => "ian", :email => '[email protected]'} | |
x.report("Datamapper creates") { | |
n.times do | |
DMUser.create(data).save! | |
end | |
} | |
x.report("Ohm creates") { | |
n.times do | |
OhmUser.create(data).save | |
end | |
} | |
x.report("raw redis creates, with json field") { | |
n.times do | |
redis.set("ian", data.to_json) | |
end | |
} | |
x.report("mongomapper creates") { | |
n.times do | |
MongoUser.new(data).save! | |
end | |
} | |
x.report("Datamapper reads") { | |
n.times do | |
DMUser.all | |
end | |
} | |
x.report("Ohm reads") { | |
n.times do | |
OhmUser.all | |
end | |
} | |
x.report("raw redis reads") { | |
n.times do | |
JSON.parse(redis.get("ian")) | |
end | |
} | |
x.report("Mongomapper reads") { | |
n.times do | |
MongoUser.all | |
end | |
} | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment