benchmark-ips icon indicating copy to clipboard operation
benchmark-ips copied to clipboard

Add Q&D driver method

Open zenspider opened this issue 5 months ago • 4 comments

I have to look up Benchmark.ips EVERY time and the (ri) doco is still a PITA.

Pls consider a simple top level driver method like so:

def quick_bench_ips(*methods, warm:nil, time:nil, show:nil)
  Benchmark.ips do |x|
    x.warmup = warm if warm
    x.time   = time if time
    x.compare!

    if show then
      max = methods.map(&:size).max
      methods.each do |name|
        val = send name
        puts "%*s: %p" % [max, name, val]
      end
      return
    end

    methods.each do |name|
      x.report(name) do |x|
        x.times { send name }
      end
    end
  end
end



def report_tally1
  # ...
end

def report_tally2
  # ...
end

def report_tally3
  # ...
end

quick_bench_ips(:report_tally1,
                :report_tally2,
                :report_tally3)

zenspider avatar Jan 05 '24 05:01 zenspider