in reply to Merged list with regex matches
$cn =~ /^(0|5|6)0+\Q$bn\E$You never know with demerphq's future optimizations in regexp speed, but I'm quite sure that for now,
will be faster than/^[056]0+/
/^(?:0|5|6)0+/
Benchmark code:
use Benchmark 'cmpthese'; my @list = ( '00012345', 'D123470', '0000123450', '0000023456', '50000 +123990' ); cmpthese -3, { charclass => sub { grep /^[056]0+/, @list }, alt => sub { grep /^(?:0|5|6)0+/, @list }, };
Benchmark result:
Benchmark: running alt, charclass, each for at least 3 CPU seconds... alt: 3 wallclock secs ( 3.00 usr + 0.00 sys = 3.00 CPU) @ 50 +5561.00/s (n=1516683) charclass: 3 wallclock secs ( 3.20 usr + 0.00 sys = 3.20 CPU) @ 53 +4972.53/s (n=1713517) Rate alt charclass alt 505561/s -- -5% charclass 534973/s 6% --
So it is indeed 5-6% faster, depending how you look at it.
|
|---|