Permalink
Browse files

benchmarks

  • Loading branch information...
Kyle Maxwell
Kyle Maxwell committed Oct 20, 2008
1 parent bbcefcd commit fba6b009cd15bb15a7ec997c76321a425eb06f30
Showing with 52 additions and 0 deletions.
  1. +1 −0 lib/keyhole/driver/local_driver.rb
  2. +51 −0 test/benchmark_local_driver.rb
@@ -9,6 +9,7 @@ class LocalDriver < Driver
def initialize(options = {})
@root = options[:root] or raise "no filesystem root provided"
+ mkdir_p @root
@keystore = SQLiteKeystore.new(options[:keystore] || File.join(@root, "keyhole.db"))
@base = options[:base]
end
@@ -0,0 +1,51 @@
+#!/usr/bin/env ruby
+require File.dirname(__FILE__) + "/../lib/keyhole"
+require "benchmark"
+require "fileutils"
+
+N = 100
+FILE_SIZE = (2 ** 16)
+
+def io
+ @io ||= StringIO.new "a" * FILE_SIZE
+ @io.rewind
+ @io
+end
+
+@tmp = File.dirname(__FILE__) + "/tmp"
+@driver ||= Keyhole::LocalDriver.new(:root => @tmp)
+io
+
+Benchmark.bm do |bm|
+ bm.report("#{N} writes") do
+ N.times do |i|
+ @driver.put(i.to_s, io)
+ end
+ end
+
+ bm.report("#{N} io reads") do
+ N.times do |i|
+ @driver.io(i.to_s).read
+ end
+ end
+
+ bm.report("#{N} gets") do
+ N.times do |i|
+ @driver.get(i.to_s).io.read
+ end
+ end
+
+ bm.report("#{N} iterative reads") do
+ @driver.keys.each do |key|
+ @driver.io(key).read
+ end
+ end
+
+ bm.report("#{N} deletes") do
+ N.times do |i|
+ @driver.delete(i.to_s)
+ end
+ end
+end
+
+FileUtils.rm_rf @tmp

0 comments on commit fba6b00

Please sign in to comment.