Re:Google Closure: How not to write Javascript
by latortuga on Thursday November 12, 2009 @10:38AM
(#937909)
I've done a lot of testing on creating strings by concatenation and it turns out that + is actually one of the slowest. It's much faster, for example, to create an array and then join it with "". Maybe try that in your test and see how it compares.
Example:
x = []
x.push("latortuga")
x.push(" is so right")
str = x.join("")
I found some of your claims questionable, so I cherry-picked one to test for myself.
I compared the time it took to run 100,000 of each of String(fn) and fn + "", and found that the results were more ambiguous and less definitive than your assertion. In fact, fn + "" was 6.6% faster on Firefox 3.5, but 15.8% slower on a recent Chromium build. In any case, the difference was, even over 100,000 runs, a few milliseconds, so it hardly seems like this particular case would be an area to focus on for optimization.I wonder how many of your other strong claims would stand up to similar testing.
Test code and results: http://gist.github.com/232944