Skip to content

Instantly share code, notes, and snippets.

@seeingidog
Created July 6, 2011 17:34
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save seeingidog/1067821 to your computer and use it in GitHub Desktop.
Save seeingidog/1067821 to your computer and use it in GitHub Desktop.
redis ORMs/mongo ORM benchmarks
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 => 'ian@ruby-code.com'}
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