Updated benchmarks to use standard benchmark library

Updated examples to latest sorting
Fixed some errors
This commit is contained in:
Adrian Madrid 2008-12-29 15:11:44 -07:00
parent f7e6cb9a83
commit e6fb6b75bf
4 changed files with 25 additions and 24 deletions

View File

@ -1,16 +1,14 @@
require "rubygems"
require "benchwarmer"
require "benchmark"
$LOAD_PATH[0,0] = File.join(File.dirname(__FILE__), '..', 'lib')
require 'mongo'
include XGen::Mongo::Driver
host = ARGV[0] || 'localhost'
port = ARGV[1] || XGen::Mongo::Driver::Mongo::DEFAULT_PORT
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 = Mongo.new(host, port).db('ruby-mongo-examples-complex')
db = XGen::Mongo::Driver::Mongo.new(host, port).db('ruby-mongo-examples-complex')
coll = db.collection('test')
coll.clear
@ -22,15 +20,19 @@ 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.warmer(TEST_COUNT) do
report "single object inserts" do
Benchmark.bmbm do |results|
results.report("single object inserts: ") {
TEST_COUNT.times {
coll.clear
arr.each {|x| coll.insert(x)}
end
report "multiple object insert" do
}
}
results.report("multiple object insert: ") {
TEST_COUNT.times {
coll.clear
coll.insert(arr)
end
}
}
end
coll.clear

View File

@ -1,5 +1,4 @@
require "rubygems"
require "benchwarmer"
class Exception
def errmsg
@ -12,8 +11,8 @@ require 'mongo'
include XGen::Mongo::Driver
host = ARGV[0] || 'localhost'
port = ARGV[1] || XGen::Mongo::Driver::Mongo::DEFAULT_PORT
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 = Mongo.new(host, port).db('ruby-mongo-blog')
@ -47,7 +46,7 @@ puts "lsmt : #{lsmt.inspect}"
puts "-" * LINE_SIZE
puts "users ordered by login ascending"
puts "-" * LINE_SIZE
users.find({}, :sort => :login).each {|x| puts "%-10.10s : %-25.25s : %-25.25s" % [x['login'], x['name'], x['email']]}
users.find({}, :sort => [{'login' => 1}]).each {|x| puts "%-10.10s : %-25.25s : %-25.25s" % [x['login'], x['name'], x['email']]}
puts "=" * LINE_SIZE
puts "Adding articles"
@ -70,7 +69,7 @@ end
puts "-" * LINE_SIZE
puts "articles ordered by title ascending"
puts "-" * LINE_SIZE
articles.find({}, :sort => :title).each {|x| puts "%-25.25s : %-25.25s" % [x['title'], x['author_id']]}
articles.find({}, :sort => [{'title' => 1}]).each {|x| puts "%-25.25s : %-25.25s" % [x['title'], x['author_id']]}
puts ">> Closing connection"
DB.close

View File

@ -12,8 +12,8 @@ require 'mongo'
include XGen::Mongo::Driver
host = ARGV[0] || 'localhost'
port = ARGV[1] || XGen::Mongo::Driver::Mongo::DEFAULT_PORT
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 = Mongo.new(host, port).db('ruby-mongo-index_test')

View File

@ -3,8 +3,8 @@ require 'mongo'
include XGen::Mongo::Driver
host = ARGV[0] || 'localhost'
port = ARGV[1] || XGen::Mongo::Driver::Mongo::DEFAULT_PORT
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 = Mongo.new(host, port).db('ruby-mongo-examples-simple')