Merge branch 'master' of git://github.com/aemadrid/mongo-ruby-driver into aemadrid
This commit is contained in:
commit
44455107dd
|
@ -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
|
|
@ -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__)
|
|
@ -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
|
||||
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in New Issue