From caa76e1023572fbb7426490140cd3833fffe5a27 Mon Sep 17 00:00:00 2001 From: John Mettraux Date: Mon, 9 Feb 2009 17:02:34 +0900 Subject: [PATCH] more benchmarking --- test/bm0.rb | 116 +++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 93 insertions(+), 23 deletions(-) diff --git a/test/bm0.rb b/test/bm0.rb index d23c998..6bed839 100644 --- a/test/bm0.rb +++ b/test/bm0.rb @@ -1,4 +1,12 @@ +# +# a bit of benchmarking +# +# some gists of runs : +# +# http://gist.github.com/60709 +# + $:.unshift('lib') require 'benchmark' @@ -7,7 +15,13 @@ N = 10_000 puts +puts Time.now.to_s puts "N is #{N}" +puts "ruby is #{RUBY_VERSION}" + +# ============================================================================== +# hashes +# ============================================================================== # # Tokyo Cabinet =============================================================== @@ -53,7 +67,7 @@ require 'rufus/tokyo/tyrant' -table = Rufus::Tokyo::Tyrant.new('127.0.0.1', 44001) +table = Rufus::Tokyo::Tyrant.new('127.0.0.1', 45000) table.clear 2.times { puts } @@ -83,32 +97,88 @@ table.close -puts + +# ============================================================================== +# tables +# ============================================================================== + +require 'faker' + +DATA = (0..N - 1).collect { |i| + { + 'name' => Faker::Name.name, + 'sex' => (i % 2) ? 'male' : 'female', + 'birthday' => DateTime.new(1972, 10, 14), + 'divisions' => (i % 2) ? 'brd' : 'dev' + } +} + +DATA1 = DATA.collect { |e| + h = e.dup + h['birthday'] = h['birthday'].to_s + h +} + # Tokyo Cabinet tables only do strings # -# Mon Feb 9 16:10:21 JST 2009 -# -# -# N is 10000 -# -# TC -# user system total real -# inserting one 0.000000 0.000000 0.000000 ( 0.000105) -# inserting N 0.060000 0.000000 0.060000 ( 0.069892) -# finding all 0.120000 0.010000 0.130000 ( 0.124895) -# iterate all 0.090000 0.000000 0.090000 ( 0.093795) -# find first 0.000000 0.000000 0.000000 ( 0.000018) -# delete first 0.000000 0.000000 0.000000 ( 0.000053) +# Tokyo Cabinet table ========================================================= # + +require 'rufus/tokyo/cabinet/table' + +FileUtils.rm_f('tmp/test.tdb') + +table = Rufus::Tokyo::Table.new('tmp/test.tdb') +table.clear + +2.times { puts } +puts 'TC table' + +Benchmark.benchmark(' ' * 20 + Benchmark::Tms::CAPTION, 20) do |b| + + b.report('inserting data') do + DATA1.each_with_index { |e, i| table[i.to_s] = e } + end + b.report('finding all') do + table.query { |q| } + end + b.report('find last') do + table[DATA.size.to_s] + end + b.report('find Alphonse') do + table.query { |q| q.add('name', :equals, DATA1[0]['name']) } + end +end + + # -# TT -# user system total real -# inserting one 0.000000 0.000000 0.000000 ( 0.000262) -# inserting N 0.160000 0.200000 0.360000 ( 1.105653) -# finding all 0.280000 0.410000 0.690000 ( 2.089718) -# iterate all 0.280000 0.400000 0.680000 ( 2.062686) -# find first 0.000000 0.000000 0.000000 ( 0.000155) -# delete first 0.000000 0.000000 0.000000 ( 0.000224) +# Tokyo Tyrant table ========================================================== # +require 'rufus/tokyo/tyrant/table' + +table = Rufus::Tokyo::TyrantTable.new('localhost', 45001) +table.clear + +2.times { puts } +puts 'TT table' + +Benchmark.benchmark(' ' * 20 + Benchmark::Tms::CAPTION, 20) do |b| + + b.report('inserting data') do + DATA1.each_with_index { |e, i| table[i.to_s] = e } + end + b.report('finding all') do + table.query { |q| } + end + b.report('find last') do + table[DATA.size.to_s] + end + b.report('find Alphonse') do + table.query { |q| q.add('name', :equals, DATA1[0]['name']) } + end +end + +puts +