2015-11-20 18:13:21 +01:00
|
|
|
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
|
2015-11-20 19:13:35 +01:00
|
|
|
#puts "no per var"
|
2015-11-20 22:51:58 +01:00
|
|
|
|
2019-07-31 20:18:03 +02:00
|
|
|
puts "#{@n} #{(@mean*1000).truncate(1)} #{((@variance / @n)*100).truncate(2)}"
|
2015-11-20 18:13:21 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
class Runner
|
2015-11-20 19:13:35 +01:00
|
|
|
def initialize
|
2015-11-20 18:13:21 +01:00
|
|
|
@stats = Stats.new
|
2015-11-24 14:33:16 +01:00
|
|
|
@cmd = ARGV.join(" ")
|
2015-11-20 18:13:21 +01:00
|
|
|
end
|
|
|
|
def run
|
2015-11-20 22:51:58 +01:00
|
|
|
while true
|
|
|
|
once
|
|
|
|
end
|
2015-11-20 18:13:21 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def once
|
|
|
|
GC.disable
|
2015-11-20 22:51:58 +01:00
|
|
|
took = Benchmark.measure { %x(#{@cmd} > /dev/null)}.real
|
2015-11-20 18:13:21 +01:00
|
|
|
GC.enable
|
|
|
|
@stats.add took
|
2015-11-20 19:13:35 +01:00
|
|
|
@stats.show
|
2015-11-20 18:13:21 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
Runner.new.run
|