public
Last active

  • Download Gist
gistfile1.rb
Ruby
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 48 49
#!/usr/bin/env ruby
 
require 'mongo'
require 'mongo/gridfs'
require 'rufus/edo'
require 'benchmark'
 
host = ENV['MONGO_RUBY_DRIVER_HOST']
port = ENV['MONGO_RUBY_DRIVER_PORT']
 
mdb = Mongo::Connection.new(host, port).db('grid-test')
tdb = Rufus::Edo::Cabinet.new('data.tch')
 
puts "WRITES ---------------------------"
 
n = 100
Benchmark.bmbm(7) do |x|
x.report('edo:') { n.times { |n| tdb["bender#{n}.jpg"] = File.read('bender.jpg') } }
x.report('gridfs:') { n.times { |n| GridFS::GridStore.open(mdb, "bender#{n}.jpg", 'w') { |f| f.write(File.read('bender.jpg')) } } }
end
 
puts
puts "READS ----------------------------"
 
n = 100
Benchmark.bmbm(7) do |x|
x.report("edo:") { n.times { |n| tdb["bender#{n}.jpg"] } }
x.report("gridfs:") { n.times { |n| GridFS::GridStore.open(mdb, "bender#{n}.jpg", 'r') { |f| f.read } } }
end
 
# WRITES ---------------------------
# Rehearsal -------------------------------------------
# edo: 0.020000 0.010000 0.030000 ( 0.034874)
# gridfs: 20.180000 0.520000 20.700000 ( 20.876570)
# --------------------------------- total: 20.730000sec
#
# user system total real
# edo: 0.010000 0.010000 0.020000 ( 0.018486)
# gridfs: 20.310000 0.300000 20.610000 ( 20.774953)
#
# READS ----------------------------
# Rehearsal -------------------------------------------
# edo: 0.010000 0.000000 0.010000 ( 0.011451)
# gridfs: 2.090000 0.010000 2.100000 ( 2.138355)
# ---------------------------------- total: 2.110000sec
#
# user system total real
# edo: 0.010000 0.010000 0.020000 ( 0.014387)
# gridfs: 2.010000 0.020000 2.030000 ( 2.062250)

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.