From 1bec6f4ca78384528d545f4a68d2732ae5e43922 Mon Sep 17 00:00:00 2001 From: Torsten Ruger Date: Fri, 20 Nov 2015 19:13:21 +0200 Subject: [PATCH] simple bench runner to do multiple runs --- test/bench/runner.rb | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 test/bench/runner.rb diff --git a/test/bench/runner.rb b/test/bench/runner.rb new file mode 100644 index 00000000..6cdf7330 --- /dev/null +++ b/test/bench/runner.rb @@ -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