e6fb6b75bf
Updated examples to latest sorting Fixed some errors
39 lines
940 B
Ruby
39 lines
940 B
Ruby
require "rubygems"
|
|
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'] || XGen::Mongo::Driver::Mongo::DEFAULT_PORT
|
|
|
|
puts "Connecting to #{host}:#{port}"
|
|
db = XGen::Mongo::Driver::Mongo.new(host, port).db('ruby-mongo-examples-complex')
|
|
coll = db.collection('test')
|
|
coll.clear
|
|
|
|
OBJS_COUNT = 100
|
|
TEST_COUNT = 100
|
|
|
|
puts "Generating benchmark data"
|
|
msgs = %w{hola hello aloha ciao}
|
|
arr = OBJS_COUNT.times.map {|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)
|
|
}
|
|
}
|
|
end
|
|
|
|
coll.clear
|