41 lines
978 B
Ruby
Executable File
41 lines
978 B
Ruby
Executable File
#!/usr/bin/env ruby
|
|
require 'rubygems'
|
|
require 'mongo'
|
|
|
|
include Mongo
|
|
include GridFS
|
|
|
|
db = Connection.new['benchmark-gridfs']
|
|
sample_data = File.open(File.join(File.dirname(__FILE__), 'sample_file.pdf'), 'r').read
|
|
GridStore.delete(db, 'mongodb.pdf')
|
|
GridStore.delete(db, 'mongodb-new.pdf')
|
|
|
|
length = sample_data.length
|
|
mb = length / 1048576.0
|
|
|
|
t1 = Time.now
|
|
@grid = Grid.new(db)
|
|
@id = @grid.put(sample_data, 'mongodb-new.pdf', :safe => true)
|
|
puts "Write: #{mb / (Time.now - t1)} mb/s"
|
|
|
|
t1 = Time.now
|
|
GridStore.open(db, 'mongodb.pdf', 'w') do |f|
|
|
f.write(sample_data)
|
|
end
|
|
puts "Write: #{mb / (Time.now - t1)} mb/s"
|
|
|
|
t1 = Time.now
|
|
@grid = Grid.new(db)
|
|
data = @grid.get(@id).read
|
|
puts "Read new: #{mb / (Time.now - t1)} mb/s"
|
|
file = db['fs.files'].find_one({:filename => 'mongodb-new.pdf'})
|
|
|
|
t1 = Time.now
|
|
old_data = GridStore.open(db, 'mongodb.pdf', 'r') do |f|
|
|
f.read
|
|
end
|
|
puts "Read: #{mb / (Time.now - t1)} mb/s"
|
|
|
|
puts sample_data == old_data
|
|
puts sample_data == data
|