Skip to content

Commit

Permalink
Update benchmark script
Browse files Browse the repository at this point in the history
Show elapsed time of the last execution.
  • Loading branch information
Hiroshi Nakamura committed Mar 27, 2012
1 parent 27166a6 commit b784697
Showing 1 changed file with 13 additions and 14 deletions.
27 changes: 13 additions & 14 deletions bench/bench.rb
Original file line number Original file line Diff line number Diff line change
@@ -1,18 +1,15 @@
# encoding: utf-8
require_relative "../lib/rbtree_map" require_relative "../lib/rbtree_map"


file = ARGV.shift or raise file = ARGV.shift or raise


def benchmark(&block) def benchmark(&block)
begin start = Time.now
start = Time.now yield
yield (Time.now - start) *1000
finished = Time.now
ensure
puts "$B7P2a;~4V(B #{(finished - start) * 1000} [msec]"
end
end end


print "$BF0:n3NG'(B..." print "動作確認..."
map = RBTreeMap.newInstance map = RBTreeMap.newInstance
File.open(file).each_line do |line| File.open(file).each_line do |line|
key, value, height = line.chomp.split(',', 3) key, value, height = line.chomp.split(',', 3)
Expand All @@ -21,15 +18,16 @@ def benchmark(&block)
File.open(file).each_line do |line| File.open(file).each_line do |line|
key, value, _ = line.split(',', 3) key, value, _ = line.split(',', 3)
if map.get(key) != value if map.get(key) != value
raise "$BCM$NIT0lCW(B #{map.get(key)} != #{value} at line #{line}" raise "値の不一致 #{map.get(key)} != #{value} at line #{line}"
end end
end end
puts "OK" puts "OK"


puts "$B%Y%s%A%^!<%/(B..." times = 5
5.times do |idx| puts "ウォームアップ... (#{times} 回)"
print "$B%Y%s%A%^!<%/(B #{idx + 1} $B2sL\(B: " (times + 1).times do |idx|
benchmark do puts "ベンチマーク: " if idx == times
elapsed = benchmark {
map = RBTreeMap.newInstance map = RBTreeMap.newInstance
File.open(file).each_line do |line| File.open(file).each_line do |line|
key, value, height = line.chomp.split(',', 3) key, value, height = line.chomp.split(',', 3)
Expand All @@ -41,5 +39,6 @@ def benchmark(&block)
puts "wrong value! #{map.get(key)} != #{value}" puts "wrong value! #{map.get(key)} != #{value}"
end end
end end
end }
puts elapsed
end end

0 comments on commit b784697

Please sign in to comment.