nijikokun/the-zen-approach

Multiline string performance

Closed this issue · 1 comments

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.

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