Next | Making Programs Faster | 29 |
substr 5.04 0.01 5.05 regex 5.71 0.00 5.71
Looking at this output, we might conclude that the substr was 11.5% faster than the regex
But something important is missing from this output
The benchmark apparatus itself is biasing the results
my ($su, $ss) = times; for (1 .. $N) { } my ($eu, $es) = times; my ($tu, $ts) = ($eu - $su, $es - $ss); my $total = $tu + $ts; printf "%20s %5.2f %5.2f %6.2f\n", "NULL", $tu, $ts, $total;
Now the output is:
NULL 1.24 0.00 1.24 substr 5.10 0.01 5.11 regex 5.69 0.00 5.69
The time actually spent doing substr was about 3.87 seconds
The time actually spent doing regex was about 4.45 seconds
The substr is actually more like 13% faster
Next | Copyright © 2003 M. J. Dominus |