Skip to content

Commit

Permalink
more benchmarking
Browse files Browse the repository at this point in the history
  • Loading branch information
jmettraux committed Feb 9, 2009
1 parent 4d54ccb commit caa76e1
Showing 1 changed file with 93 additions and 23 deletions.
116 changes: 93 additions & 23 deletions test/bm0.rb
@@ -1,4 +1,12 @@

#
# a bit of benchmarking
#
# some gists of runs :
#
# http://gist.github.com/60709
#

$:.unshift('lib')

require 'benchmark'
Expand All @@ -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 ===============================================================
Expand Down Expand Up @@ -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 }
Expand Down Expand Up @@ -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

0 comments on commit caa76e1

Please sign in to comment.