Merge branch 'master' of git://github.com/aemadrid/mongo-ruby-driver into aemadrid

This commit is contained in:
Jim Menard 2008-12-05 15:32:18 -05:00
commit 44455107dd
4 changed files with 61 additions and 1 deletions

36
examples/benchmarks.rb Normal file
View File

@ -0,0 +1,36 @@
require "rubygems"
require "benchwarmer"
$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
puts "Connecting to #{host}:#{port}"
db = 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.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
end
coll.clear

19
examples/irb.rb Executable file
View File

@ -0,0 +1,19 @@
#!/usr/bin/env ruby
org_argv = ARGV.dup
ARGV.clear
require 'irb'
$LOAD_PATH[0,0] = File.join(File.dirname(__FILE__), '..', 'lib')
require 'mongo'
include XGen::Mongo::Driver
host = org_argv[0] || 'localhost'
port = org_argv[1] || XGen::Mongo::Driver::Mongo::DEFAULT_PORT
puts "Connecting to #{host}:#{port} on DB"
DB = Mongo.new(host, port).db('ruby-mongo-examples-irb')
puts "Starting IRB session..."
IRB.start(__FILE__)

View File

@ -3,7 +3,11 @@ require 'mongo'
include XGen::Mongo::Driver
db = Mongo.new.db('ruby-mongo-demo')
host = ARGV[0] || 'localhost'
port = ARGV[1] || XGen::Mongo::Driver::Mongo::DEFAULT_PORT
puts "Connecting to #{host}:#{port}"
db = Mongo.new(host, port).db('ruby-mongo-examples-simple')
coll = db.collection('test')
coll.clear

View File

@ -32,6 +32,7 @@ module XGen
end
def insert(*objects)
objects = objects.first if objects.size == 1 && objects.first.is_a?(Array)
@db.insert_into_db(@name, objects)
end