summaryrefslogtreecommitdiff
path: root/lib/Benchmark.pm
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Benchmark.pm')
-rw-r--r--lib/Benchmark.pm10
1 files changed, 10 insertions, 0 deletions
diff --git a/lib/Benchmark.pm b/lib/Benchmark.pm
index 1d272a7d33..90e54a66ee 100644
--- a/lib/Benchmark.pm
+++ b/lib/Benchmark.pm
@@ -904,6 +904,16 @@ sub timethis{
$n = $forn if defined $forn;
+ if ($t->elapsed($style) < 0) {
+ # due to clock granularity and variable CPU speed and load,
+ # on quick code with a small number of loops, it's possible for
+ # the empty loop to appear to take longer than the real loop
+ # (e.g. 1 tick verses 0 ticks). This leads to a negative elapsed
+ # time. In this case, floor it at zero, to stop bizarre results.
+ print " (warning: too few iterations for a reliable count)\n";
+ $t->[$_] = 0 for 1..4;
+ }
+
# A conservative warning to spot very silly tests.
# Don't assume that your benchmark is ok simply because
# you don't get this warning!