Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re^2: String concatenation

by chromatic (Archbishop)
on Apr 11, 2012 at 20:31 UTC ( #964618=note: print w/ replies, xml ) Need Help??


in reply to Re: String concatenation
in thread String concatenation

Both of the interpolation forms compile to the same optree. Perl does the same work for both of them. Any difference between their benchmarks is noise.

Given that, the time difference between concatenation and interpolation (which do have different optrees) is insignificant.


Comment on Re^2: String concatenation
Re^3: String concatenation
by Riales (Hermit) on Apr 11, 2012 at 20:37 UTC

    Ah, yes--I ran my script a couple more times and it seems that the two interpolates and the dot are pretty much the same but the join is consistently slower. I envy the monks with an understanding of what Perl does internally!

      I envy the monks with an understanding of what Perl does internally!
      You don't need an understanding of what Perl does internally to find out whether two code snippets compile to the same optree. Use -MO=Terse (or -MO=Concise).
Re^3: String concatenation
by dave_the_m (Parson) on Apr 11, 2012 at 20:57 UTC
    In fact it goes further than that; the dot form also compiles to the same optree as the interpolation forms.

    Dave.

      Hmmm.
      $ perl -MO=Terse -e '$v1.$v2.$v3' LISTOP (0x9dc5fe0) leave [1] OP (0x9dc6768) enter COP (0x9dd0650) nextstate BINOP (0x9dd06e0) concat [2] BINOP (0x9dd05b0) concat [1] UNOP (0x9dd0688) null [15] SVOP (0x9dd07e8) gvsv GV (0x9dcaa30) *v1 UNOP (0x9dd0578) null [15] SVOP (0x9dd0630) gvsv GV (0x9dcaa58) *v2 UNOP (0x9dd05d0) null [15] SVOP (0x9dcf9e0) gvsv GV (0x9dcaae4) *v3 -e syntax OK $ perl -MO=Terse -e '"$v1$v2$v3"' LISTOP (0x8b92778) leave [1] OP (0x8b88768) enter COP (0x8b92650) nextstate UNOP (0x8b926e0) null [67] OP (0x8b918d0) null [3] BINOP (0x8b925d0) concat [2] BINOP (0x8b925b0) concat [1] UNOP (0x8b92688) null [15] SVOP (0x8b927e8) gvsv GV (0x8b8ca44) *v1 UNOP (0x8b92578) null [15] SVOP (0x8b92630) gvsv GV (0x8b8cb34) *v2 UNOP (0x8b91920) null [15] SVOP (0x8b91a10) gvsv GV (0x8b8cae4) *v3 -e syntax OK
      Similar, but subtle differences.

        What actually executes is the same:

        $ perl -MO=Terse,-exec -e '$v1.$v2.$v3' OP (0x16e5ad0) enter COP (0x1817650) nextstate PADOP (0x16e6eb0) gvsv GV (0x16e3b68) *v1 PADOP (0x16e5b80) gvsv GV (0x16e3b98) *v2 BINOP (0x16e5a50) concat [3] PADOP (0x16e4c00) gvsv GV (0x16bee88) *v3 BINOP (0x16d5aa0) concat [5] LISTOP (0x16e4ca0) leave [1] -e syntax OK $ perl -MO=Terse,-exec -e '"$v1$v2$v3"' OP (0x1ecc200) enter COP (0x200d6b0) nextstate PADOP (0x1edac60) gvsv GV (0x1ed9b80) *v1 PADOP (0x1edbd40) gvsv GV (0x1ed9ca0) *v2 BINOP (0x1edba90) concat [3] PADOP (0x1edba50) gvsv GV (0x1eb4e88) *v3 BINOP (0x1ecbaa0) concat [5] LISTOP (0x1edb9d0) leave [1] -e syntax OK

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (16)
As of 2014-08-20 15:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (116 votes), past polls