nmerouze (owner)

Forks

Revisions

gist: 190245 Download_button fork
public
Public Clone URL: git://gist.github.com/190245.git
Embed All Files: show embed
benchmarks-results.txt #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
Ruby 1.8.6 w/o C extension
==========================
                               user system total real
single object inserts: 3.450000 0.160000 3.610000 ( 3.779446)
multiple object insert: 2.190000 0.020000 2.210000 ( 2.223418)
find_one: 0.070000 0.000000 0.070000 ( 0.087103)
 
Ruby 1.8.6 w/ C extension
=========================
                               user system total real
single object inserts: 2.110000 0.140000 2.250000 ( 2.277138)
multiple object insert: 1.410000 0.020000 1.430000 ( 1.451186)
find_one: 0.050000 0.000000 0.050000 ( 0.061466)
 
Ruby 1.9.1 w/o C extension
==========================
                               user system total real
single object inserts: 1.950000 0.170000 2.120000 ( 2.162213)
multiple object insert: 1.180000 0.020000 1.200000 ( 1.196612)
find_one: 0.040000 0.000000 0.040000 ( 0.061222)
 
Ruby 1.9.1 w/ C extension
=========================
                               user system total real
single object inserts: 1.110000 0.160000 1.270000 ( 1.426076)
multiple object insert: 0.360000 0.010000 0.370000 ( 0.383090)
find_one: 0.030000 0.000000 0.030000 ( 0.049040)
 
JRuby 1.3.1
===========
                               user system total real
single object inserts: 2.621000 0.000000 2.621000 ( 2.621000)
multiple object insert: 1.524000 0.000000 1.524000 ( 1.524000)
find_one: 0.122000 0.000000 0.122000 ( 0.122000)
 
 
JRuby 1.3.1 with Java driver
============================
                               user system total real
single object inserts: 0.666000 0.000000 0.666000 ( 0.666000)
multiple object insert: 0.189000 0.000000 0.189000 ( 0.189000)
find_one: 0.030000 0.000000 0.030000 ( 0.030000)
jruby-benchmark.rb #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
require "java"
require "benchmark"
require "mongo.jar"
 
import "com.mongodb.Mongo"
import "com.mongodb.DBCollection"
import "com.mongodb.BasicDBObject"
 
db = Mongo.new('ruby-mongo-examples')
coll = db.get_collection('test')
coll.drop
 
OBJS_COUNT = 100
TEST_COUNT = 100
 
puts "Generating benchmark data"
msgs = %w{hola hello aloha ciao}
arr = (0..OBJS_COUNT).collect do |x|
  obj = BasicDBObject.new
  obj.put("number", x)
  obj.put("rndm", rand(5)+1)
  obj.put("msg", msgs[rand(4)])
  obj
end
 
puts "Running benchmark"
Benchmark.bmbm do |results|
  results.report("single object inserts: ") {
    TEST_COUNT.times {
      coll.drop
      arr.each {|x| coll.insert(x)}
    }
  }
  results.report("multiple object insert: ") {
    TEST_COUNT.times {
      coll.drop
      coll.insert(arr)
    }
  }
  results.report("find_one: ") {
    TEST_COUNT.times {
      coll.find_one(BasicDBObject.new("number", 0))
    }
  }
end
 
coll.drop
pure-ruby-benchmark.rb #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
require "benchmark"
 
$LOAD_PATH[0,0] = File.join(File.dirname(__FILE__), '..', 'lib')
require 'mongo'
 
host = ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost'
port = ENV['MONGO_RUBY_DRIVER_PORT'] || Mongo::Connection::DEFAULT_PORT
 
puts "Connecting to #{host}:#{port}"
db = Mongo::Connection.new(host, port).db('ruby-mongo-examples')
coll = db.collection('test')
coll.clear
 
OBJS_COUNT = 100
TEST_COUNT = 100
 
puts "Generating benchmark data"
msgs = %w{hola hello aloha ciao}
arr = (0..OBJS_COUNT).collect {|x| { :number => x, :rndm => (rand(5)+1), :msg => msgs[rand(4)] }}
 
puts "Running benchmark"
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)
    }
  }
  results.report("find_one: ") {
    TEST_COUNT.times {
      coll.find_one(:number => 0)
    }
  }
end
 
coll.clear