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.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
|
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.
|
|