Created
December 26, 2012 05:19
-
-
Save arthurnn/4378113 to your computer and use it in GitHub Desktop.
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 'moped' | |
require 'mongo' | |
include Mongo | |
@client = MongoClient.new('localhost', 27017) | |
@db = @client['mongo_benchmark'] | |
@coll = @db['mongo10gen'] | |
@coll.remove | |
session = Moped::Session.new([ "127.0.0.1:27017" ]) | |
session.use "mongo_benchmark" | |
session[:moped].find.remove_all | |
puts "BSON::ObjectId.new" | |
Benchmark.bm(12) do |x| | |
x.report("10gen-mongo") do | |
500000.times do |i| | |
BSON::ObjectId.new | |
end | |
end | |
x.report("moped") do | |
500000.times do |i| | |
Moped::BSON::ObjectId.new | |
end | |
end | |
end | |
%w(to_s generation_time data hash).each do |w| | |
puts "\n\nBSON::ObjectId.#{w}" | |
Benchmark.bm(12) do |x| | |
x.report("10gen-mongo") do | |
500000.times do |i| | |
BSON::ObjectId.new.send(w.to_sym) | |
end | |
end | |
x.report("moped") do | |
500000.times do |i| | |
Moped::BSON::ObjectId.new.send(w.to_sym) | |
end | |
end | |
end | |
end | |
puts "\n\ninserts" | |
Benchmark.bm(12) do |x| | |
x.report("10gen-mongo") do | |
15000.times do |i| | |
@coll.insert({'a' => i+1}) | |
end | |
end | |
x.report("moped") do | |
session.with(safe: true) do |safe| | |
15000.times do |i| | |
safe[:moped].insert(a: i+1) | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment