Next | Making Programs Faster | 30 |
Perl comes with a benchmarking module called Benchmark
The previous slide's benchmark looks like this:
use Benchmark; my $N = shift || 1000000; my $s = shift || "The quick brown fox jumps over the lazy dog"; timethese($N, { substr => sub { substr($s, 0, 3) = "abc" }, regex => sub { $s =~ s/.../abc/s }, });
regex: 7 wallclock secs ( 7.85 usr + 0.00 sys = 7.85 CPU) @ 127388.54/s (n=1000000) substr: 7 wallclock secs ( 8.24 usr + 0.00 sys = 8.24 CPU) @ 121359.22/s (n=1000000)
Benchmark says that the regex is about 5% faster
It tries to do its own adjustments for error
Next | Copyright © 2003 M. J. Dominus |