Javascript: String concatenate in IE7 more than 1000 times slower than Opera!



  • When writing a javascript function that returns a string built from pieces of other strings, I was wondering which was faster: Build it directly to a string or push it on an array that will be joined on return.

    I wrote a little test script and tried it in Firefox 2, Opera 9 and IE7. Opera was very fast and did the string concatenate in only 0.2s. Firefox took returned after 4.1s. After 20 minutes Internet Explorer 7 still hadn’t returned!!!

    This made me curios so I had to do some more testing. The result was a little surprising.

    With strings Firefox was up to 17 times slower than Opera depending on the size of the data. I had to stop measuring on IE after it was more than 700 times slower than Opera.

    With arrays that are joined on return Opera was the fastest one up to a certain point, then it was surprisingly IE who was the fastest one. On the largest data IE returned after only 3 seconds, FF come second with 18s and at last OP on 25s!

    Below you find the results of my measurements and the javascript code used.

    CharsTimesIE7 stringOP9 stringFF2 stringIE7 arrayOP9 arrayFF2 array
    40001000


    1600
    20005001600
    2000050007800
    4000010000


    16047
    2000005000047663147
    2400006000064373147
    320000800002175831266
    400000100000
    31250313157407
    800000200000
    787666562971250
    1200000300000
    14015799844852203
    1600000400000
    187267212816413703
    2000000500000
    235417215938125265
    2400000600000
    28135828193836887234
    2800000700000
    67347781226680009313
    3200000800000
    112031001625471290612235
    3600000900000
    162341262429221867115016
    40000001000000
    218131528132042496918250
    // Javascript
    function test_array(size) {
    var s=[];
    for (var i=0; i < size; ++i) { s.push("TEST");}
    return s.join("");
    }
    function test_string(size) {
    var s="";
    for (var i=0; i < size; ++i) { s += "TEST";}
    return s;
    }
    function timer(func,size) {
    var start = new Date().getTime();
    return func(size).length + ": " + (new Date().getTime() - start );
    }

    var i=100000;

    alert(i + " " + timer(test_array,i));
    i+=100000; alert(i + " " + timer(test_array,i));
    i+=100000; alert(i + " " + timer(test_array,i));

  • Garbage Person

    TRWTF is using Javascript for that much text.



  • Obviously, that must have been fixed in IE8. If you won't proof the opposite, that is.





  • FF3 claims to have much improved it's javascript speed. Those numbers might be interesting.   



  • @tster said:

    FF3 claims to have much improved it's javascript speed. Those numbers might be interesting.   

    Here, Firefox 3 RC 3 (or so), completes this test in about 2100ms, where "100000 [concatenations] completed in 43[ms]". For comparison, IE7 completes that test in about 16000ms, where "100000 completed in 407", but the record is 469ms for a single test. IE8 seems to perform worse though, at least as far as my tests got using the linked performance test.



  •  Well, it seems ie7 has ripped string manipulation code from konqueror. This browser has about the same awfull results :)  It's not so much important, you can't log in to thedailywtf with konqueror anyway :D



  • @tchize said:

    Well, it seems ie7 has ripped string manipulation code from konqueror. This browser has about the same awfull results :)

    BUT KONQUEROR PASSES THE ACID3 TEST!!!



    (Where IE8 is a HUGE failure. IE7 even huger!)


Log in to reply