Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # MongoDB Java driver vs Ruby Driver with JRuby 1.3.1
- #
- # user system total real
- # java driver (find) 2.266000 0.000000 2.266000 ( 2.266000)
- # ruby driver (find) 6.790000 0.000000 6.790000 ( 6.790000)
- # java driver (create) 0.602000 0.000000 0.602000 ( 0.602000)
- # ruby driver (create) 3.963000 0.000000 3.963000 ( 3.963000)
- require "java"
- require "benchmark"
- require "rubygems"
- require "mongo"
- require "mongo.jar"
- class MongoJava
- import "com.mongodb.Mongo"
- import "com.mongodb.DBCollection"
- import "com.mongodb.BasicDBObject"
- import "com.mongodb.DBObject"
- def initialize
- @db = Mongo.new("mongojavatest")
- @coll = @db.get_collection("testCollection")
- @coll.drop
- doc = BasicDBObject.new
- doc.put "name", "MongoDB"
- @coll.insert(doc)
- end
- def create
- doc = BasicDBObject.new
- doc.put "name", "MongoDB"
- @coll.insert(doc)
- end
- def find
- @coll.find_one
- end
- end
- class MongoRuby
- def initialize
- @db = Mongo::Connection.new.db("mongorubytest")
- @coll = @db.collection("testCollection")
- @coll.insert({ "name" => "MongoDB" })
- end
- def create
- @coll.insert({ "name" => "MongoDB" })
- end
- def find
- @coll.find_one
- end
- end
- jdriver = MongoJava.new
- rdriver = MongoRuby.new
- TIMES = 10_000
- Benchmark.bm do |x|
- x.report("java driver (find)") { TIMES.times { |n| jdriver.find } }
- x.report("ruby driver (find)") { TIMES.times { |n| rdriver.find } }
- x.report("java driver (create)") { TIMES.times { |n| jdriver.create } }
- x.report("ruby driver (create)") { TIMES.times { |n| rdriver.create } }
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement