M
Mark Seger
I constructed a very simply step to compare two ways to do pattern
matching and found using the '|' to check for two patterns to be a lot
slower than 2 separate tests of one pattern each. Most surprising!
Consider the following:
#!/usr/bin/perl
$z='ZZZZZZZZZZZZZZZZZZZZZ';
for ($i=0; $i<1000000; $i++)
{
$a=1 if $z=~/xxxxx|yyyyy/;
# $a=1 if $z=~/xxxxx/ or $z=~/yyyyy/;
}
[root@dl380-1 collectl]# time ./test.pl
real 0m4.526s
user 0m4.320s
sys 0m0.000s
if I comment out the first test and uncomment the second one I get
[root@dl380-1 collectl]# time ./test.pl
real 0m0.702s
user 0m0.690s
sys 0m0.010s
As one might expect, when the strings get bigger or the number of tests
increase, the difference in test runs get even bigger. Comments?
-mark
matching and found using the '|' to check for two patterns to be a lot
slower than 2 separate tests of one pattern each. Most surprising!
Consider the following:
#!/usr/bin/perl
$z='ZZZZZZZZZZZZZZZZZZZZZ';
for ($i=0; $i<1000000; $i++)
{
$a=1 if $z=~/xxxxx|yyyyy/;
# $a=1 if $z=~/xxxxx/ or $z=~/yyyyy/;
}
[root@dl380-1 collectl]# time ./test.pl
real 0m4.526s
user 0m4.320s
sys 0m0.000s
if I comment out the first test and uncomment the second one I get
[root@dl380-1 collectl]# time ./test.pl
real 0m0.702s
user 0m0.690s
sys 0m0.010s
As one might expect, when the strings get bigger or the number of tests
increase, the difference in test runs get even bigger. Comments?
-mark