From e6fb6b75bfc5a9d4a38c3ac4b50072c283da261a Mon Sep 17 00:00:00 2001 From: Adrian Madrid Date: Mon, 29 Dec 2008 15:11:44 -0700 Subject: [PATCH] Updated benchmarks to use standard benchmark library Updated examples to latest sorting Fixed some errors --- examples/benchmarks.rb | 32 +++++++++++++++++--------------- examples/blog.rb | 9 ++++----- examples/index_test.rb | 4 ++-- examples/simple.rb | 4 ++-- 4 files changed, 25 insertions(+), 24 deletions(-) diff --git a/examples/benchmarks.rb b/examples/benchmarks.rb index ec24307..deaf4b5 100644 --- a/examples/benchmarks.rb +++ b/examples/benchmarks.rb @@ -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 - coll.clear - arr.each {|x| coll.insert(x)} - end - report "multiple object insert" do - coll.clear - coll.insert(arr) - end +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 diff --git a/examples/blog.rb b/examples/blog.rb index 3499974..8c966d8 100644 --- a/examples/blog.rb +++ b/examples/blog.rb @@ -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 diff --git a/examples/index_test.rb b/examples/index_test.rb index 39a503d..7e3bfc1 100644 --- a/examples/index_test.rb +++ b/examples/index_test.rb @@ -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') diff --git a/examples/simple.rb b/examples/simple.rb index 3535b23..5a46c2d 100644 --- a/examples/simple.rb +++ b/examples/simple.rb @@ -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')