nijikokun / the-zen-approach

JavaScript Styleguide, can be applied to other things as well.
MIT License
168 stars 16 forks source link

Multiline string performance #5

Closed octachrome closed 10 years ago

octachrome commented 10 years ago

In section 9i on multiline strings, you say that

If you are appending to the dom [].join happens to be the most performant

This is a bit unclear, because it doesn't have anything to do with the dom specifically; [].join is just faster than string1 += string2 when you are building up a large string in a loop (probably because of having to allocate lots of string objects).

Having said that, I updated the tests, and += actually outperforms [].join in this test case. Perhaps join only takes the lead when the number of loop iterations gets significantly higher.

nijikokun commented 10 years ago

Yes, you are correct, I think it is on a high number of loops is where [].join becomes more performant than a string.