Created
July 30, 2012 16:12
-
-
Save jasonholmes/3208096 to your computer and use it in GitHub Desktop.
Comparison of mappers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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