Created
September 21, 2009 13:32
-
-
Save nmerouze/190245 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
Ruby 1.8.6 w/o C extension | |
========================== | |
user system total real | |
single object inserts: 3.450000 0.160000 3.610000 ( 3.779446) | |
multiple object insert: 2.190000 0.020000 2.210000 ( 2.223418) | |
find_one: 0.070000 0.000000 0.070000 ( 0.087103) | |
Ruby 1.8.6 w/ C extension | |
========================= | |
user system total real | |
single object inserts: 2.110000 0.140000 2.250000 ( 2.277138) | |
multiple object insert: 1.410000 0.020000 1.430000 ( 1.451186) | |
find_one: 0.050000 0.000000 0.050000 ( 0.061466) | |
Ruby 1.9.1 w/o C extension | |
========================== | |
user system total real | |
single object inserts: 1.950000 0.170000 2.120000 ( 2.162213) | |
multiple object insert: 1.180000 0.020000 1.200000 ( 1.196612) | |
find_one: 0.040000 0.000000 0.040000 ( 0.061222) | |
Ruby 1.9.1 w/ C extension | |
========================= | |
user system total real | |
single object inserts: 1.110000 0.160000 1.270000 ( 1.426076) | |
multiple object insert: 0.360000 0.010000 0.370000 ( 0.383090) | |
find_one: 0.030000 0.000000 0.030000 ( 0.049040) | |
JRuby 1.3.1 | |
=========== | |
user system total real | |
single object inserts: 2.621000 0.000000 2.621000 ( 2.621000) | |
multiple object insert: 1.524000 0.000000 1.524000 ( 1.524000) | |
find_one: 0.122000 0.000000 0.122000 ( 0.122000) | |
JRuby 1.3.1 with Java driver | |
============================ | |
user system total real | |
single object inserts: 0.666000 0.000000 0.666000 ( 0.666000) | |
multiple object insert: 0.189000 0.000000 0.189000 ( 0.189000) | |
find_one: 0.030000 0.000000 0.030000 ( 0.030000) |
This file contains hidden or 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 "java" | |
require "benchmark" | |
require "mongo.jar" | |
import "com.mongodb.Mongo" | |
import "com.mongodb.DBCollection" | |
import "com.mongodb.BasicDBObject" | |
db = Mongo.new('ruby-mongo-examples') | |
coll = db.get_collection('test') | |
coll.drop | |
OBJS_COUNT = 100 | |
TEST_COUNT = 100 | |
puts "Generating benchmark data" | |
msgs = %w{hola hello aloha ciao} | |
arr = (0..OBJS_COUNT).collect do |x| | |
obj = BasicDBObject.new | |
obj.put("number", x) | |
obj.put("rndm", rand(5)+1) | |
obj.put("msg", msgs[rand(4)]) | |
obj | |
end | |
puts "Running benchmark" | |
Benchmark.bmbm do |results| | |
results.report("single object inserts: ") { | |
TEST_COUNT.times { | |
coll.drop | |
arr.each {|x| coll.insert(x)} | |
} | |
} | |
results.report("multiple object insert: ") { | |
TEST_COUNT.times { | |
coll.drop | |
coll.insert(arr) | |
} | |
} | |
results.report("find_one: ") { | |
TEST_COUNT.times { | |
coll.find_one(BasicDBObject.new("number", 0)) | |
} | |
} | |
end | |
coll.drop |
This file contains hidden or 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" | |
$LOAD_PATH[0,0] = File.join(File.dirname(__FILE__), '..', 'lib') | |
require 'mongo' | |
host = ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost' | |
port = ENV['MONGO_RUBY_DRIVER_PORT'] || Mongo::Connection::DEFAULT_PORT | |
puts "Connecting to #{host}:#{port}" | |
db = Mongo::Connection.new(host, port).db('ruby-mongo-examples') | |
coll = db.collection('test') | |
coll.clear | |
OBJS_COUNT = 100 | |
TEST_COUNT = 100 | |
puts "Generating benchmark data" | |
msgs = %w{hola hello aloha ciao} | |
arr = (0..OBJS_COUNT).collect {|x| { :number => x, :rndm => (rand(5)+1), :msg => msgs[rand(4)] }} | |
puts "Running benchmark" | |
Benchmark.bmbm do |results| | |
results.report("single object inserts: ") { | |
TEST_COUNT.times { | |
coll.clear | |
arr.each {|x| coll.insert(x)} | |
} | |
} | |
results.report("multiple object insert: ") { | |
TEST_COUNT.times { | |
coll.clear | |
coll.insert(arr) | |
} | |
} | |
results.report("find_one: ") { | |
TEST_COUNT.times { | |
coll.find_one(:number => 0) | |
} | |
} | |
end | |
coll.clear |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment