Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

executable file 47 lines (38 sloc) 1.01 kb
#!/usr/bin/env ruby
require 'rubygems'
require 'mongo'
include Mongo
db = Connection.new['benchmark-gridfs']
sample_data = File.open(File.join(File.dirname(__FILE__), 'sample_file.pdf'), 'r').read
db['fs.files'].remove
db['fs.chunks'].remove
T = 5
length = sample_data.length
mb = T * length / 1048576.0
@grid = Grid.new(db)
@grid_file_system = GridFileSystem.new(db)
t1 = Time.now
ids = []
T.times do |n|
ids << @grid.put(sample_data, :filename => "mongodb-new-#{n}.pdf")
end
puts "Grid Write: #{mb / (Time.now - t1)} mb/s"
t1 = Time.now
T.times do |n|
@grid_file_system.open("mongodb.pdf-#{n}", 'w') do |f|
f.write(sample_data)
end
end
puts "GridFileSystem Write: #{mb / (Time.now - t1)} mb/s"
t1 = Time.now
T.times do |n|
data = @grid.get(ids[n]).read
end
puts "Grid Read: #{mb / (Time.now - t1)} mb/s"
t1 = Time.now
T.times do |n|
old_data = @grid_file_system.open("mongodb.pdf-#{n}", 'r') do |f|
f.read
end
end
puts "GridFileSystem Read: #{mb / (Time.now - t1)} mb/s"
Jump to Line
Something went wrong with that request. Please try again.