Hmm can you plz show me the practical difference to perl?

lanx@nc10-ubuntu:~$ python Python 2.5.2 (r252:60911, Jan 20 2010, 23:16:55) ... >>> str="123" >>> str+="4" >>> str '1234'

The only thing I can think of are runtime issues :

I've read that in JS  str+="a";str+="b" takes 40% longer than str=str+"a"+"b", because strings have to be copied...

But in perl the second version needs much longer...

DB<1> $str="";$t=time;for (1..100000) {$str=$str."a"."b"};print time +-$t 13 DB<2> $str="";$t=time;for (1..1000000) {$str.="a";$str.="b"};print t +ime-$t 1

Actually the same code in python has similar benchmarks

>>> for i in range(1, 1000000): ... str+="a"+"b" ... >>> str="" >>> for i in range(1, 100000): ... str=str+"a"+"b" ...

So where is the practical difference?

Cheers Rolf

UPDATE: Maybe not a good benchmark, since the growing of $str plays a too important role ...

DB<1> $t=time;for (1..10000000) {$str="";$str.="a"."b";};print time- +$t 10 DB<2> $t=time;for (1..10000000) {$str="";$str=$str."a";$str.="b";};p +rint time-$t 17 DB<3> $t=time;for (1..10000000) {$str="";$str=$str."a"."b";};print t +ime-$t 15

In reply to Re: programming languages and immutable data types by LanX
in thread programming languages and immutable data types by mattk1

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



  • 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, details, 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, summary, 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.