Say I have a benchmark result like so:
0.020000 0.000000 0.020000 ( 0.020197)
I'm creating this with something like
Benchmark.bm do |x|
x.report { run_a_method() }
end
This represents the time required to call a method foo
one time.
I want to produce a benchmark which shows the result of running foo
3 times, but only requires calling the method once.
This can be done by simply multiplying the values in the first benchmark by 3.
Is there any way to do this?
Edit
I'm not really appreciating the comments that this is "not a correct benchmark". I recognize that it is more accurate to run it multiple times, but these are resource-intensive tests and I am simply projecting an expected time frame for multiple runs.
In other words, my use-case is just to create an expectation for the multiple-run time, not a wholly accurate one.
The problem with extrapolating, as you suggest, is that it compounds any errors you've got. Running N rounds of a single benchmark tends to even out any irregularities. Running 1 round and multiplying by N actually amplifies any irregularities.
So the short answer is you can't. You need to run multiple tests to get a better idea of performance. If these tests take a long time to run you either have to eat the cost or find ways of running them more quickly, or in parallel somehow.
Figured it out myself.
Initially I tried the following:
But I eventually thought to try
which had the intended effect of doubling the values in the benchmark.
For example, if the
report
variable points toThe running
puts (report[0] * 2)
showswhich is the multiplied value I was going for.