On May 12, 2004, at 4:55 AM, Radoslaw Zielinski wrote:
Save the expense of the regexp as well. :-)
You underestimate the optimizations of a good regular expression that simply checks a character anchored at the end of a string, my friend:
% cat try #!/usr/bin/perl -w
use strict; use Benchmark;
my $uri = '/this/that/theother'; my $uri2 = '/this/that/theother';
timethese(10000000, { regex => sub { return if $uri =~ m{/$}; }, regex2 => sub { return if $uri2 =~ m{/$}; }, substr => sub { return if substr($uri, -1, 1) ne '/'; }, substr2 => sub { return if substr($uri2, -1, 1) ne '/'; }, });
% try
Benchmark: timing 10000000 iterations of regex, regex2, substr, substr2...
regex: 5 wallclock secs ( 4.26 usr + 0.04 sys = 4.30 CPU) @ 2325581.40/s (n=10000000)
regex2: 4 wallclock secs ( 4.35 usr + -0.01 sys = 4.34 CPU) @ 2304147.47/s (n=10000000)
substr: 7 wallclock secs ( 7.52 usr + 0.01 sys = 7.53 CPU) @ 1328021.25/s (n=10000000)
substr2: 7 wallclock secs ( 7.53 usr + 0.00 sys = 7.53 CPU) @ 1328021.25/s (n=10000000)
But both are obscenely fast, really. :-)
Regards,
David
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]