In this sort of situation, you'll want to aim for the code inside the 5,000,000 iterations to be as minimal as possible.
I ran a few commandline tests comparing the smartmatch with a regex. The regex was 5-10 times faster. Here's a typical run:
$ time perl -Mstrict -Mwarnings -E ' my @x = ((q{AXXX}) x 4000, qw{BXXX CXXX}); my $y = q{BXXX}; my $c = 0; for (1 .. 5000) { $y ~~ @x && ++$c; } say qq{count=$c}; ' count=5000 real 0m1.128s user 0m1.122s sys 0m0.004s $ time perl -Mstrict -Mwarnings -e ' my @x = ((q{AXXX}) x 4000, qw{BXXX CXXX}); my $y = q{BXXX}; my $c = 0; my $z = join q{|} => @x; for (1 .. 5000) { $z =~ m{\b$y\b} && ++$c; } print qq{count=$c\n}; ' count=5000 real 0m0.142s user 0m0.138s sys 0m0.003s
See also: Benchmark
-- Ken
In reply to Re: Need a replacement method for older version of perl
by kcott
in thread Need a replacement method for older version of perl
by vivomancer
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |