Skip to content

@jasonholmes /verdict.rb
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Comparison of mappers
require "benchmark"
require "mongo_mapper"
require "mongoid"
class MongoMapperModel
include MongoMapper::Document
key :title, String
key :content, String
key :published_at, Time
end
MongoMapper.connection = Mongo::Connection.new("127.0.0.1", 27017)
MongoMapper.database = "mongo_mapper_verdict"
MongoMapperModel.delete_all
class MongoidModel
include Mongoid::Document
field :title, type: String
field :content, type: String
field :published_at, type: Time
end
Mongoid.configure do |c|
c.connect_to("mongoid_verdict")
end
MongoidModel.delete_all
Benchmark.bm do |bench|
bench.report("MongoMapper create") do
100_000.times do |n|
MongoMapperModel.create(title: "#{n}", content: "#{n}", published_at: Time.now)
end
end
bench.report("Mongoid create") do
100_000.times do |n|
MongoidModel.create(title: "#{n}", content: "#{n}", published_at: Time.now)
end
end
# MongoMapper create 50.240000 1.330000 51.570000 ( 51.575320)
# Mongoid create 34.430000 1.130000 35.560000 ( 35.554373)
end
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.