diff options
author | David Mitchell <davem@iabyn.com> | 2019-11-12 13:18:43 +0000 |
---|---|---|
committer | David Mitchell <davem@iabyn.com> | 2019-11-12 13:33:16 +0000 |
commit | f0206e819891ea9f375f3443e0a4d3ccf02acac8 (patch) | |
tree | 7fd6acc6f88b83a9748992f5ff94854bd6b39104 /cpan | |
parent | 5fd49982f066fe0bba7131745725d7f61278b51c (diff) | |
download | perl-f0206e819891ea9f375f3443e0a4d3ccf02acac8.tar.gz |
Memoize: fix test timing
NB: this distro is upstream-CPAN, but there hasn't been a new release in
7 years, so I'm patching this intermittently false positive test
directly in blead.
I reported this issue 4 years ago as
https://rt.cpan.org/Public/Bug/Display.html?id=108382
cpan/Memoize/t/speed.t occasionally fails tests 2 and 5 in bleadperl
smokes.
This is because the time deltas (using "time") have a granularity of 1
sec. The basic test is: run fib() for at least 10 secs, then run again
with memoize and check that it takes less than 1/10th of that time.
However, the first measurement may be exactly 10 secs, while the second
run (no matter how speedy) may be 1 sec if it passes over a tick
boundary. 0.001 is then added to it to avoid division by zero.
The test is ($ELAPSED/$ELAPSED2 > 10). With $ELAPSED = 10 and
$ELAPSED2 = 1.001, the test fails. The easy fix is to run for at least
11 secs rather than 10.
Diffstat (limited to 'cpan')
-rw-r--r-- | cpan/Memoize/t/speed.t | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/cpan/Memoize/t/speed.t b/cpan/Memoize/t/speed.t index 6d21906573..c4b838192d 100644 --- a/cpan/Memoize/t/speed.t +++ b/cpan/Memoize/t/speed.t @@ -56,7 +56,7 @@ $N = 1; $ELAPSED = 0; -my $LONG_RUN = 10; +my $LONG_RUN = 11; while (1) { my $start = time; @@ -88,10 +88,11 @@ $COUNT=0; $start = time; $RESULT2 = fib($N); $ELAPSED2 = time - $start + .001; # prevent division by 0 errors - print (($RESULT == $RESULT2) ? "ok 1\n" : "not ok 1\n"); # If it's not ten times as fast, something is seriously wrong. +print "# ELAPSED2=$ELAPSED2 seconds.\n"; print (($ELAPSED/$ELAPSED2 > 10) ? "ok 2\n" : "not ok 2\n"); + # If it called the function more than $N times, it wasn't memoized properly print (($COUNT > $N) ? "ok 3\n" : "not ok 3\n"); @@ -100,8 +101,8 @@ $COUNT = 0; $start = time; $RESULT2 = fib($N); $ELAPSED2 = time - $start + .001; # prevent division by 0 errors - print (($RESULT == $RESULT2) ? "ok 4\n" : "not ok 4\n"); +print "# ELAPSED2=$ELAPSED2 seconds.\n"; print (($ELAPSED/$ELAPSED2 > 10) ? "ok 5\n" : "not ok 5\n"); # This time it shouldn't have called the function at all. print ($COUNT == 0 ? "ok 6\n" : "not ok 6\n"); |