Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

benchmarks

  • Loading branch information...
commit fba6b009cd15bb15a7ec997c76321a425eb06f30 1 parent bbcefcd
authored October 19, 2008
1  lib/keyhole/driver/local_driver.rb
@@ -9,6 +9,7 @@ class LocalDriver < Driver
9 9
     
10 10
     def initialize(options = {})
11 11
       @root = options[:root] or raise "no filesystem root provided"
  12
+      mkdir_p @root
12 13
       @keystore = SQLiteKeystore.new(options[:keystore] || File.join(@root, "keyhole.db"))
13 14
       @base = options[:base]
14 15
     end
51  test/benchmark_local_driver.rb
... ...
@@ -0,0 +1,51 @@
  1
+#!/usr/bin/env ruby
  2
+require File.dirname(__FILE__) + "/../lib/keyhole"
  3
+require "benchmark"
  4
+require "fileutils"
  5
+
  6
+N = 100
  7
+FILE_SIZE = (2 ** 16)
  8
+
  9
+def io
  10
+  @io ||= StringIO.new "a" * FILE_SIZE
  11
+  @io.rewind
  12
+  @io
  13
+end
  14
+
  15
+@tmp = File.dirname(__FILE__) + "/tmp"
  16
+@driver ||= Keyhole::LocalDriver.new(:root => @tmp)
  17
+io
  18
+
  19
+Benchmark.bm do |bm|
  20
+  bm.report("#{N} writes") do 
  21
+    N.times do |i|
  22
+      @driver.put(i.to_s, io)
  23
+    end
  24
+  end
  25
+  
  26
+  bm.report("#{N} io reads") do 
  27
+    N.times do |i|
  28
+      @driver.io(i.to_s).read
  29
+    end
  30
+  end
  31
+  
  32
+  bm.report("#{N} gets") do 
  33
+    N.times do |i|
  34
+      @driver.get(i.to_s).io.read
  35
+    end
  36
+  end
  37
+  
  38
+  bm.report("#{N} iterative reads") do 
  39
+    @driver.keys.each do |key|
  40
+      @driver.io(key).read
  41
+    end
  42
+  end
  43
+  
  44
+  bm.report("#{N} deletes") do 
  45
+    N.times do |i|
  46
+      @driver.delete(i.to_s)
  47
+    end
  48
+  end
  49
+end
  50
+
  51
+FileUtils.rm_rf @tmp

0 notes on commit fba6b00

Please sign in to comment.
Something went wrong with that request. Please try again.