$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,
/^[056]0+/
will be faster than
/^(?: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.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.