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 "rubygems"
require "benchwarmer" require "benchmark"
$LOAD_PATH[0,0] = File.join(File.dirname(__FILE__), '..', 'lib') $LOAD_PATH[0,0] = File.join(File.dirname(__FILE__), '..', 'lib')
require 'mongo' require 'mongo'
include XGen::Mongo::Driver host = ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost'
port = ENV['MONGO_RUBY_DRIVER_PORT'] || XGen::Mongo::Driver::Mongo::DEFAULT_PORT
host = ARGV[0] || 'localhost'
port = ARGV[1] || XGen::Mongo::Driver::Mongo::DEFAULT_PORT
puts "Connecting to #{host}:#{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 = db.collection('test')
coll.clear 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)] }} arr = OBJS_COUNT.times.map {|x| { :number => x, :rndm => (rand(5)+1), :msg => msgs[rand(4)] }}
puts "Running benchmark" puts "Running benchmark"
Benchmark.warmer(TEST_COUNT) do Benchmark.bmbm do |results|
report "single object inserts" do results.report("single object inserts: ") {
coll.clear TEST_COUNT.times {
arr.each {|x| coll.insert(x)} coll.clear
end arr.each {|x| coll.insert(x)}
report "multiple object insert" do }
coll.clear }
coll.insert(arr) results.report("multiple object insert: ") {
end TEST_COUNT.times {
coll.clear
coll.insert(arr)
}
}
end end
coll.clear coll.clear

View File

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

View File

@ -12,8 +12,8 @@ require 'mongo'
include XGen::Mongo::Driver include XGen::Mongo::Driver
host = ARGV[0] || 'localhost' host = ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost'
port = ARGV[1] || XGen::Mongo::Driver::Mongo::DEFAULT_PORT port = ENV['MONGO_RUBY_DRIVER_PORT'] || XGen::Mongo::Driver::Mongo::DEFAULT_PORT
puts ">> Connecting to #{host}:#{port}" puts ">> Connecting to #{host}:#{port}"
db = Mongo.new(host, port).db('ruby-mongo-index_test') db = Mongo.new(host, port).db('ruby-mongo-index_test')

View File

@ -3,8 +3,8 @@ require 'mongo'
include XGen::Mongo::Driver include XGen::Mongo::Driver
host = ARGV[0] || 'localhost' host = ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost'
port = ARGV[1] || XGen::Mongo::Driver::Mongo::DEFAULT_PORT port = ENV['MONGO_RUBY_DRIVER_PORT'] || XGen::Mongo::Driver::Mongo::DEFAULT_PORT
puts "Connecting to #{host}:#{port}" puts "Connecting to #{host}:#{port}"
db = Mongo.new(host, port).db('ruby-mongo-examples-simple') db = Mongo.new(host, port).db('ruby-mongo-examples-simple')