banker (owner)

Revisions

gist: 234367 Download_button fork
public
Public Clone URL: git://gist.github.com/234367.git
Embed All Files: show embed
GridFS Benchmark.rb #
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
50
51
52
53
54
55
56
require 'rubygems'
require 'mongo'
require 'mongo/gridfs'
include Mongo
include GridFS
 
require 'benchmark'
 
@db = Mongo::Connection.new.db('stuff')
 
# Write some sample data.
data = ""
0.upto(40000) do |n|
  data << '1'
end
 
# Write to the file system
File.open('test.txt', 'w') do |f|
  f.print data
end
 
if !GridStore.exist? @db, 'grid.txt'
  GridStore.open @db, 'grid.txt', 'w' do |f|
    f.print @data
  end
end
 
def test_file
  100.times do
    File.open('test.txt', 'r') do |f|
      f.read
    end
  end
end
 
def test_grid
  100.times do
    GridStore.read @db, 'grid.txt'
  end
end
 
Benchmark.bmbm do |x|
  x.report('file') { test_file }
  x.report('grid') { test_grid }
end
 
# Results on Macbook Pro 2GB with MongoDB 1.1.3
#Rehearsal ----------------------------------------
#file 0.010000 0.010000 0.020000 ( 0.016901)
#grid 0.070000 0.010000 0.080000 ( 0.111597)
#------------------------------- total: 0.100000sec
#
# user system total real
#file 0.010000 0.010000 0.020000 ( 0.022519)
#grid 0.070000 0.010000 0.080000 ( 0.109611)