in reply to Differences between " " and ' '?

A Super Search pulled up a thread earlier this year where not only was this benchmarked, but some of the meta-questions where talked about, such as when to use which.

Replies are listed 'Best First'.
Re^2: Differences between " " and ' '?
by pg (Canon) on Jul 31, 2005 at 17:53 UTC

    That was an interesting thread. Base on those numbers, double and single quote really does not have much speed difference and the difference is not consistent. bass_warrior's testing was meaningless, he made up cases to drive a pre-determined conclusion.

    I slightly modified the first set of benchmark provided by Anonymous Monk, and when the string is a little bit longer, the chance of winning between double and single quote becomes really close to 50-50:

    use warnings; use Benchmark("cmpthese"); cmpthese(-1, { "double", q !eval q {$a = "this is a string" x 10}!, 'single', q !eval q {$b = 'this is a string' x 10}!, });

    Conclusion: the difference between single and double quote are more functional than performance.

    Update: when I tried x 100, double seems to win more. In a way, it shows that length of the string matters here. The overall conclusion stays, the speed difference does not mean much.

      Your post seemed to be incorrect. I don't believe you are interpreting the output in the right fashion. The double still shows up as being FASTER, abnormally faster with your example.

      use warnings; use Benchmark("cmpthese"); cmpthese(-1, { "double", q !eval q {$a = "this is a string" x 10}!, 'single', q !eval q {$b = 'this is a string' x 10}!, });

      Not just did it show a speed increase but 46%, a quite significant one:

      Rate double single
      double 39422/s -- -31%
      single 57420/s 46% --


      Evan Carroll
      www.evancarroll.com

        I was correct. The problem is that you only ran that program once. The whole point in my post and the other thread Tanktalus mentioned is that, if you ran exactly the same testing multiple times, neither double or single wins consistently.

        My testing environment is Xp, Perl 5.8.4