Permalink
Browse files

Update benchmark script

  • Loading branch information...
1 parent c247efb commit 869e1f325b34e642cc91fd6f4da805869511ad8b @nahi nahi committed Mar 28, 2012
Showing with 15 additions and 27 deletions.
  1. +15 −27 bench/bench.rb
View
42 bench/bench.rb
@@ -1,36 +1,22 @@
# encoding: utf-8
require_relative "../lib/rbtree_map"
-file = ARGV.shift or raise
-
-def benchmark(&block)
- start = Time.now
- yield
- (Time.now - start) *1000
-end
+class BenchmarkApp
+ TIMES = 5
-print "動作確認..."
-map = RBTreeMap.newInstance
-File.open(file).each_line do |line|
- key, value, height = line.chomp.split(',', 3)
- map.put(key, value)
-end
-File.open(file).each_line do |line|
- key, value, _ = line.split(',', 3)
- if map.get(key) != value
- raise "値の不一致 #{map.get(key)} != #{value} at line #{line}"
+ def run(file)
+ TIMES.times do
+ execute(file)
+ end
+ start = Time.now
+ execute(file)
+ puts (Time.now - start) * 1000
end
-end
-puts "OK"
-times = 5
-puts "ウォームアップ... (#{times} 回)"
-(times + 1).times do |idx|
- puts "ベンチマーク: " if idx == times
- elapsed = benchmark {
+ def execute(file)
map = RBTreeMap.newInstance
File.open(file).each_line do |line|
- key, value, height = line.chomp.split(',', 3)
+ key, value, _ = line.split(',', 3)
map.put(key, value)
end
File.open(file).each_line do |line|
@@ -39,6 +25,8 @@ def benchmark(&block)
puts "wrong value! #{map.get(key)} != #{value}"
end
end
- }
- puts elapsed
+ end
end
+
+file = ARGV.shift or raise
+BenchmarkApp.new.run(file)

0 comments on commit 869e1f3

Please sign in to comment.