Advertisement
Guest User

Untitled

a guest
Dec 1st, 2011
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.59 KB | None | 0 0
  1. # MongoDB Java driver vs Ruby Driver with JRuby 1.3.1
  2. #
  3. # user system total real
  4. # java driver (find) 2.266000 0.000000 2.266000 ( 2.266000)
  5. # ruby driver (find) 6.790000 0.000000 6.790000 ( 6.790000)
  6. # java driver (create) 0.602000 0.000000 0.602000 ( 0.602000)
  7. # ruby driver (create) 3.963000 0.000000 3.963000 ( 3.963000)
  8.  
  9. require "java"
  10. require "benchmark"
  11. require "rubygems"
  12. require "mongo"
  13. require "mongo.jar"
  14.  
  15. class MongoJava
  16. import "com.mongodb.Mongo"
  17. import "com.mongodb.DBCollection"
  18. import "com.mongodb.BasicDBObject"
  19. import "com.mongodb.DBObject"
  20.  
  21. def initialize
  22. @db = Mongo.new("mongojavatest")
  23. @coll = @db.get_collection("testCollection")
  24. @coll.drop
  25.  
  26. doc = BasicDBObject.new
  27. doc.put "name", "MongoDB"
  28. @coll.insert(doc)
  29. end
  30.  
  31. def create
  32. doc = BasicDBObject.new
  33. doc.put "name", "MongoDB"
  34. @coll.insert(doc)
  35. end
  36.  
  37. def find
  38. @coll.find_one
  39. end
  40. end
  41.  
  42. class MongoRuby
  43. def initialize
  44. @db = Mongo::Connection.new.db("mongorubytest")
  45. @coll = @db.collection("testCollection")
  46. @coll.insert({ "name" => "MongoDB" })
  47. end
  48.  
  49. def create
  50. @coll.insert({ "name" => "MongoDB" })
  51. end
  52.  
  53. def find
  54. @coll.find_one
  55. end
  56. end
  57.  
  58. jdriver = MongoJava.new
  59. rdriver = MongoRuby.new
  60.  
  61. TIMES = 10_000
  62.  
  63. Benchmark.bm do |x|
  64. x.report("java driver (find)") { TIMES.times { |n| jdriver.find } }
  65. x.report("ruby driver (find)") { TIMES.times { |n| rdriver.find } }
  66. x.report("java driver (create)") { TIMES.times { |n| jdriver.create } }
  67. x.report("ruby driver (create)") { TIMES.times { |n| rdriver.create } }
  68. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement