Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

A quick change to your benchmark measures more accurately what we are talking about. Assume the evals and string qoutes are right because you lost me in there somewhere.

use strict; use warnings; use Benchmark("cmpthese"); cmpthese(-1, { 'double' , q !eval q {$a = "this is a string \$i"}!, 'single' , q !eval q {$b = 'this is a string $i'}!, 'double no $', q !eval q {$a = "this is a string"}!, 'single no $', q !eval q {$b = 'this is a string'}!, }); __DATA__ C:\test>perl interpolation_bench.pl Rate double single double no $ single no $ double 22226/s -- -16% -17% -17% single 26331/s 18% -- -2% -2% double no $ 26733/s 20% 2% -- 0% single no $ 26733/s 20% 2% 0% -- C:\test>perl interpolation_bench.pl Rate double single double no $ single no $ double 21065/s -- -20% -21% -21% single 26331/s 25% -- -1% -2% double no $ 26714/s 27% 1% -- -0% single no $ 26756/s 27% 2% 0% -- C:\test>perl interpolation_bench.pl Rate double single single no $ double no $ double 21966/s -- -17% -18% -18% single 26551/s 21% -- -1% -1% single no $ 26733/s 22% 1% -- -1% double no $ 26947/s 23% 1% 1% -- C:\test>perl interpolation_bench.pl Rate double single single no $ double no $ double 22226/s -- -14% -16% -17% single 25960/s 17% -- -1% -3% single no $ 26331/s 18% 1% -- -2% double no $ 26733/s 20% 3% 2% -- C:\test>perl interpolation_bench.pl Rate double double no $ single single no $ double 20785/s -- -19% -21% -23% double no $ 25551/s 23% -- -3% -5% single 26211/s 26% 3% -- -3% single no $ 27019/s 30% 6% 3% --

You see a consistent win for single quotes, I don't think it is enough to worry about though. If you are dealing with 100k strings and you want to decide if you should sinle or double quote them, then you probably made a bad choice to load 100k variables ;)

Update: Added benchmarks for strings with no $ in them. Looks like perl must do a prescan to see if it needs work or not. I could of course be completely crazy.


___________
Eric Hodges

In reply to Re^3: To Single Quote or to Double Quote: a benchmark by eric256
in thread To Single Quote or to Double Quote by NateTut

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • 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 or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (4)
As of 2021-10-25 15:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My first memorable Perl project was:







    Results (89 votes). Check out past polls.

    Notices?