11 print "# Warning: I'm testing the speedup. This might take up to sixty seconds.\n";
19 fib($n-1) + fib($n-2);
25 until ($ELAPSED > 10) {
30 $ELAPSED = time - $start;
31 print "# fib($N) took $ELAPSED seconds.\n" if $N % 1 == 0;
34 print "# OK, fib($N) was slow enough; it took $ELAPSED seconds.\n";
42 $ELAPSED2 = time - $start + .001; # prevent division by 0 errors
44 print (($RESULT == $RESULT2) ? "ok 1\n" : "not ok 1\n");
45 # If it's not ten times as fast, something is seriously wrong.
46 print (($ELAPSED/$ELAPSED2 > 10) ? "ok 2\n" : "not ok 2\n");
47 # If it called the function more than $N times, it wasn't memoized properly
48 print (($COUNT > $N) ? "ok 3\n" : "not ok 3\n");
50 # Do it again. Should be even faster this time.
53 $ELAPSED2 = time - $start + .001; # prevent division by 0 errors
56 print (($RESULT == $RESULT2) ? "ok 4\n" : "not ok 4\n");
57 print (($ELAPSED/$ELAPSED2 > 10) ? "ok 5\n" : "not ok 5\n");
58 # This time it shouldn't have called the function at all.
59 print ($COUNT ? "ok 6\n" : "not ok 6\n");