simple bench runner to do multiple runs

This commit is contained in:
Torsten Ruger 2015-11-20 19:13:21 +02:00
parent da4003c30a
commit 1bec6f4ca7

41
test/bench/runner.rb Normal file
View File

@ -0,0 +1,41 @@
require "benchmark"
class Stats
def initialize
@n = 0
@mean = 0.0
@variance = 0.0
end
attr_reader :n , :mean , :variance
def add(x)
@n = @n + 1
delta = x - @mean
@mean = @mean + delta/@n
@variance = @variance + delta*(x - @mean)
end
def show
puts "no per var"
puts "#{@n} #{@mean} #{@variance}"
end
end
class Runner
def initialize num = 20
@stats = Stats.new
@cmd = ARGV[0]
@interations = num
end
def run
@interations.times { once }
@stats.show
end
def once
GC.disable
took = Benchmark.measure { %x("#{@cmd}")}.real
GC.enable
@stats.add took
end
end
Runner.new.run