Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: Performance penalty of using qr//

by LanX (Saint)
on Dec 21, 2017 at 04:11 UTC ( [id://1205957]=note: print w/replies, xml ) Need Help??


in reply to Performance penalty of using qr//

Sorry, your benchmark is too complicated, I can't easily tell how often the inner loop is executed.

If it's just several times then your results may be explained by the overhead to initialize qr.

Another guess is to try $s =~ /$re/; instead of $s =~ $re; (which is admittedly counterintuitive)

Can't test, sorry.

Cheers Rolf
(addicted to the Perl Programming Language and ☆☆☆☆ :)
Wikisyntax for the Monastery

Replies are listed 'Best First'.
Re^2: Performance penalty of using qr//
by Athanasius (Archbishop) on Dec 21, 2017 at 06:44 UTC

    Hi LanX,

    The inner for loops are each executed 3,789,182 times.

    And yes, I originally had $s =~ /$re/ instead of $s =~ $re — it made no appreciable difference.

    Update: Deparsing suggests that Perl adds the slashes anyway:

    16:57 >perl -we "my $q = qr/^(\d+)$/; 123 =~ $q; print qq[$1\n];" 123 16:57 >perl -MO=Deparse -we "my $q = qr/^(\d+)$/; 123 =~ $q; print qq[ +$1\n];" BEGIN { $^W = 1; } my $q = qr/^(\d+)$/; 123 =~ /$q/; print "$1\n"; -e syntax OK 16:57 >

    Cheers,

    Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,

      hmm .... could be a regression.

      If for some reason the scalar falls back to string interpolation instead of using the compilated code this could explain the penalty and wouldn't break the tests.

      A simplified benchmark for all platforms x versions would be nice.

      Cheers Rolf
      (addicted to the Perl Programming Language and ☆☆☆☆ :)
      Wikisyntax for the Monastery

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1205957]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (7)
As of 2024-03-29 12:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found