2008-12-29 22:11:44 +00:00
|
|
|
require "benchmark"
|
2008-12-05 00:08:57 +00:00
|
|
|
|
|
|
|
$LOAD_PATH[0,0] = File.join(File.dirname(__FILE__), '..', 'lib')
|
|
|
|
require 'mongo'
|
|
|
|
|
2008-12-29 22:11:44 +00:00
|
|
|
host = ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost'
|
|
|
|
port = ENV['MONGO_RUBY_DRIVER_PORT'] || XGen::Mongo::Driver::Mongo::DEFAULT_PORT
|
2008-12-05 00:08:57 +00:00
|
|
|
|
|
|
|
puts "Connecting to #{host}:#{port}"
|
2009-02-03 17:15:35 +00:00
|
|
|
db = XGen::Mongo::Driver::Mongo.new(host, port).db('ruby-mongo-examples')
|
2008-12-05 00:08:57 +00:00
|
|
|
coll = db.collection('test')
|
|
|
|
coll.clear
|
|
|
|
|
|
|
|
OBJS_COUNT = 100
|
|
|
|
TEST_COUNT = 100
|
|
|
|
|
|
|
|
puts "Generating benchmark data"
|
|
|
|
msgs = %w{hola hello aloha ciao}
|
2009-02-10 15:43:47 +00:00
|
|
|
arr = (0..OBJS_COUNT).collect {|x| { :number => x, :rndm => (rand(5)+1), :msg => msgs[rand(4)] }}
|
2008-12-05 00:08:57 +00:00
|
|
|
|
|
|
|
puts "Running benchmark"
|
2008-12-29 22:11:44 +00:00
|
|
|
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)
|
|
|
|
}
|
|
|
|
}
|
2009-02-10 15:43:47 +00:00
|
|
|
results.report("find_first: ") {
|
|
|
|
TEST_COUNT.times {
|
|
|
|
coll.find_first(:number => 0)
|
|
|
|
}
|
|
|
|
}
|
2008-12-05 00:08:57 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
coll.clear
|