simple bench runner to do multiple runs
This commit is contained in:
parent
da4003c30a
commit
1bec6f4ca7
41
test/bench/runner.rb
Normal file
41
test/bench/runner.rb
Normal 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
|
Loading…
Reference in New Issue
Block a user