2009-12-15 19:13:04 +00:00
|
|
|
#!/usr/bin/env ruby
|
|
|
|
require 'rubygems'
|
|
|
|
require 'mongo'
|
2009-12-16 19:03:15 +00:00
|
|
|
#require 'ruby-prof'
|
2009-12-15 19:13:04 +00:00
|
|
|
|
|
|
|
include Mongo
|
|
|
|
include GridFS
|
|
|
|
|
|
|
|
db = Connection.new['benchmark-gridfs']
|
|
|
|
sample_data = File.open(File.join(File.dirname(__FILE__), 'sample_file.pdf'), 'r').read
|
2009-12-15 21:30:03 +00:00
|
|
|
GridStore.delete(db, 'mongodb.pdf')
|
2009-12-15 19:13:04 +00:00
|
|
|
|
|
|
|
length = sample_data.length
|
|
|
|
mb = length / 1048576.0
|
|
|
|
|
|
|
|
t1 = Time.now
|
2009-12-16 19:03:15 +00:00
|
|
|
#RubyProf.start
|
2009-12-15 19:13:04 +00:00
|
|
|
GridStore.open(db, 'mongodb.pdf', 'w') do |f|
|
|
|
|
f.write(sample_data)
|
|
|
|
end
|
2009-12-16 19:03:15 +00:00
|
|
|
#result = RubyProf.stop
|
2009-12-15 19:13:04 +00:00
|
|
|
puts "Write: #{mb / (Time.now - t1)} mb/s"
|
2009-12-16 19:03:15 +00:00
|
|
|
#printer = RubyProf::FlatPrinter.new(result)
|
|
|
|
#printer.print(STDOUT, 0)
|
|
|
|
|
2009-12-15 19:13:04 +00:00
|
|
|
|
|
|
|
t1 = Time.now
|
|
|
|
GridStore.open(db, 'mongodb.pdf', 'r') do |f|
|
|
|
|
data = f.read
|
|
|
|
end
|
|
|
|
puts "Read: #{mb / (Time.now - t1)} mb/s"
|