Benchmark.pm: bail out earlier on zero delta
authorDavid Mitchell <davem@iabyn.com>
Mon, 21 Oct 2013 12:07:19 +0000 (13:07 +0100)
committerDavid Mitchell <davem@iabyn.com>
Mon, 21 Oct 2013 12:50:26 +0000 (13:50 +0100)
commit24755e36b3a8716d2d99c4ce1c1775c0807affa7
treeaf82bf14a2e7f6f51eef6817f0790ae95cada080
parent083ace8f9342a384107f7068fbedccaffa078b08
Benchmark.pm: bail out earlier on zero delta

countit(), which runs code for $n seconds, performs an initial
set of calibration loops to find out roughly how many iterations
are required to burn 0.1 CPU secs more in the code loop than in the empty
loop (which is then used to guesstimate how many iterations to do for the
main loop).

This calibration is designed to bail out if we consistently get <= 0
difference between the empty loop and the code loop; however, this
bailout can take too long: it looks for a run of 17 *consecutive* zero
deltas during 2048, 4096,8192,... iterations, which means it won't fail
until approx 131 million empty + code iterations are run, even if
the zeroes are consecutive. Of course if just by random noise one delta
is infinitesimally > 0, then the count is reset and the exponential count
continues.

The net effect of this is that the calibration loop can loop forever on
'small' code.

This commit makes it additionally bail out of the calibration loop if
running the iterations for a particular value of N takes more than 8
CPU seconds, while still giving zero delta.
lib/Benchmark.pm