I read this article at Usable Type and said to myself - true, true, true, true, WTF?
So I did a quick test:
- Concatenating 3 long strings: without ~135ms (45ms) [25ms] {33ms}, with ~220ms (120ms) [40ms] {65ms}
- Concatenating 12 shorter strings: without ~215ms (190ms) [85ms] {90ms}, with ~470ms (180ms) [105ms] {165ms}
The tests were done on my laptop on Windows Vista in Firefox (IE7) [Safari3] {Opera 9.2}, the function was repeated 10000 times. It seems that you’re better off without using array.join(), though it might be an option for huge joins in IE.
I wonder what sparked the idea - I’ve seen the use of arrays for string operations in Flash - string.split(old).join(new) for replacing until a proper method was available. I’ve never thought about abusing JavaScript that way…
On a side note - have you noticed that Firefox was significantly slower than others?
Update: I created a test page so you can test your browsers and post a comment…
