Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
require 'rubygems'
require 'dm-core'
require 'dm-timestamps'
require 'rbench'
DataMapper.setup(:default, "mysql://localhost/logs_test")
DataMapper.setup(:mongo, "mongo://localhost/logs_test")
class MysqlLog
include DataMapper::Resource
property :id, Serial
property :message, String, :length => 512, :required => true
property :user_id, Integer
property :created_at, Time, :default => lambda { Time.now }
belongs_to :user
end
class MongoLog
include DataMapper::Mongo::Resource
def self.default_repository_name; :mongo; end
property :id, ObjectID, :required => false
property :message, String, :length => 512, :required => true
property :user_id, Integer
property :created_at, Time, :default => lambda { Time.now }
belongs_to :user, :repository => :default
end
class User
include DataMapper::Resource
property :id, Serial
property :name, String
has n, :mongo_logs, :repository => :mongo
has n, :mysql_logs
end
DataMapper.auto_migrate!
MongoLog.all.destroy!
user = User.create(:name => 'Foo')
TIMES = 1000
RBench.run(TIMES) do
column :times
column :mysql, :title => 'MySQL'
column :mongo, :title => "Mongo"
column :diff, :compare => [:mysql, :mongo]
report 'create log', TIMES do
mysql { user.mysql_logs.create(:message => 'this is a log') }
mongo { user.mongo_logs.create(:message => 'this is a log') }
end
report 'read logs with limit=20', TIMES do
mysql { user.mysql_logs.all(:limit => 20) }
mongo { user.mongo_logs.all(:limit => 20) }
end
report 'update log message', TIMES do
mysql { user.mysql_logs.first(:message => 'this is a log').update(:message=> 'this is still a log') }
mongo { user.mongo_logs.first(:message => 'this is a log').update(:message=> 'this is still a log') }
end
end
| MySQL | Mongo | DIFF |
-----------------------------------------------------------------------
create log x999 | 26.824 | 1.308 | 20.51x |
read logs with limit=20 x999 | 0.215 | 0.211 | 1.02x |
update log message x999 | 27.832 | 3.919 | 7.10x |
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.