Wizards,
I thought regexp was the fastest way to pull strings out of another string; certainly faster than substr(). It seems I was wrong, as the following code showed
#--------------------------------------------------------------------------------------------------------
use strict;
use warnings;
use Benchmark qw(timethese cmpthese);
my $data_line = ' <TD class=xc01>Wanted data goes here</TD>';
my $tag;
my $r = timethese( 1_000_000, {
'new way' => sub {
$data_line =~ />([^\<]+)\</;
$tag = $1;
},
'old way' => sub {
$tag = substr( $data_line, 19, -5 );
},
} );
cmpthese( $r );
#---------------------------------------------------------------------------------------------------------
This showed that "old way" ran more than 1200% faster. That's right, twelve hundred per cent. Did I get my facts mixed up in thinking that regexp beat all, or is there something obfuscated going on?????
Thanks!
Deane
_______________________________________________ ActivePerl mailing list [email protected] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
