Skip to content

Instantly share code, notes, and snippets.

| AR 2.2.2 | DM 0.10.0 | DIFF |
-----------------------------------------------------------------------------------------
Model#id x100000 | 1.139 | 0.421 | 2.70x |
Model.new (instantiation) x10000 | 0.319 | 0.025 | 12.93x |
Model.new (setting attributes) x10000 | 1.140 | 0.587 | 1.94x |
Model.get specific (not cached) x10000 | 4.756 | 5.782 | 0.82x |
Model.get specif
| AR 2.2.2 | DM 0.10.0 | DIFF |
-----------------------------------------------------------------------------------------
Model#id x100000 | 1.184 | 0.441 | 2.68x |
Model.new (instantiation) x10000 | 0.411 | 0.024 | 16.91x |
Model.new (setting attributes) x10000 | 1.098 | 0.597 | 1.84x |
Model.get specific (not cached) x10000 | 5.675 | 6.248 | 0.91x |
Model.get specific (cached) x10000 | 5.753 | 0.274 | 20.99x |
Model.first x10000 | 4.857 | 4.698 | 1.03x |
Model.all limit(100) x1000 | 11.598 | 9.329 | 1.24x |
Model.all limit(100) with relationship x1000 | 24.752 | 68.050 | 0.36x |
Looks like we've got a broken IdentityMap but at least creates are 16x faster, lol :D
| MySQL Adapter | Mongo Adapter | DIFF |
-------------------------------------------------------------------------------------------
Model#id x100000 | 0.779 | 0.955 | 0.82x |
Model.get specific (not cached) x10000 | 8.739 | 18.586 | 0.47x |
Model.get specific (cached) x10000 | 0.205 | 18.169 | 0.01x |
Model.first x10000 | 6.838 | 15.949 | 0.43x |
Model.all limit(100)
#!/usr/bin/env ruby
require "rubygems"
require "benchmark"
# DM Adapter
require "dm-core"
require "dm-timestamps"
require "dm-pager"
class User
include DataMapper::Resource
property :id, Serial
property :foo, String, :unique_index => :foo_bar
property :bar, String, :unique_index => :foo_bar
end
#/usr/bin/ruby
require 'rubygems'
require 'dm-core'
class Foo
include DataMapper::Resource
def self.default_repository_name; :alt; end
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
@solnic
solnic / mysql_and_mongodb_example.rb
Created March 3, 2010 11:11
This code uses dm-core from snusnu's active_support branch and dm-mongo-adapter from master
require 'rubygems'
require 'dm-core'
DataMapper.setup(:default, "mysql://localhost/examples")
DataMapper.setup(:logs, "mongo://localhost/examples")
class LoggedEvent
include DataMapper::Mongo::Resource
def self.default_repository_name; :logs; end
class LoggedEvent
include DataMapper::Mongo::Resource
property :id, ObjectID
property :type, Discriminator
property :message, String
property :custom_attributes, Hash
property :created_at, DateTime
end
class ApplicationController < ActionController::Base
protect_from_forgery
rescue_from MerbToRails3::ControllerExceptions::Base, :with => :handle_exception
protected
def handle_exception(e)
if action_name = e.action_name
self.status = e.status