Skip to content

Instantly share code, notes, and snippets.

@jasonholmes
Created July 30, 2012 16:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jasonholmes/3208096 to your computer and use it in GitHub Desktop.
Save jasonholmes/3208096 to your computer and use it in GitHub Desktop.
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