From 478c94529fcdc49120fbbc98f7be109ecefa444e Mon Sep 17 00:00:00 2001 From: Justin Balthrop Date: Thu, 19 Nov 2009 11:13:58 -0800 Subject: [PATCH] add benchmark script --- test/benchmark.rb | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 test/benchmark.rb diff --git a/test/benchmark.rb b/test/benchmark.rb new file mode 100644 index 0000000..d00a8f1 --- /dev/null +++ b/test/benchmark.rb @@ -0,0 +1,31 @@ +require 'rubygems' +require File.dirname(__FILE__) + '/../lib/bdb/simple' +require 'benchmark' + +N = 10_000 +A = [5, 6, "foo", :bar, "bar", {}, :foo, [1,2,4], true, [1,2,3], false, [1], [2], nil].collect {|i| Marshal.dump(i)} + +puts "compare_absolute (#{N} times)" +t = Benchmark.measure do + N.times do + A.sort {|a,b| Bdb::Simple.compare_absolute(Marshal.load(a), Marshal.load(b)) } + end +end +puts t + +puts "compare_hash (#{N} times)" +t = Benchmark.measure do + N.times do + A.sort {|a,b| Marshal.load(a).hash <=> Marshal.load(b).hash } + end +end +puts t + +puts "compare_raw (#{N} times)" +t = Benchmark.measure do + N.times do + A.sort + end +end +puts t +