Seemed odd to me, so I ran it on 5.8.8 and the current bleadperl 5.11. The absolute numbers for my computer are, of course, different, but the general observation holds for 5.11. The really disturbing part is that 5.8.8 executes the atomic1/2 cases at about the same speed as "normal". Oh, and on a side note: The difference in execution speed of 5.11's "normal" and 5.8.8's "normal" may be due to 5.11 being a debugging build and all, so it's not necessarily significant.
#!/usr/bin/perl
use strict;
use warnings;
use version;
use Benchmark qw(cmpthese);
my $str = "bea" x 100;
my $re = qr/(?:be|ea|a)/;
cmpthese(-2, {
atomic1 => sub { die if $str =~ m/(?>$re+)\d/ },
atomic2 => sub { die if $str =~ m/(?>$re)+\d/ },
normal => sub { die if $str =~ m/$re+\d/ },
( version->new($]) >= version->new("5.10.0")
? (posessive => sub { die if $str =~ m/$re++\d/ })
: ()
),
});
__END__
5.8.8:
Rate normal atomic2 atomic1
normal 5000/s -- -4% -18%
atomic2 5208/s 4% -- -15%
atomic1 6132/s 23% 18% --
5.11:
Rate posessive atomic1 atomic2 normal
posessive 59.9/s -- -1% -97% -97%
atomic1 60.4/s 1% -- -97% -97%
atomic2 1953/s 3159% 3134% -- -9%
normal 2156/s 3500% 3472% 10% --
I'm hoping for demerphq to chime in with an explanation. :) Cheers, Steffen
-
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.
|