Javascript Split Performance
I'm sure you've all seen code like this in JS:
var args = 'now later today tomorrow'.split(' ')
Anyone know why that's faster than this:
args = ['now', 'later', 'today', 'tomorrow']
开发者_如何转开发(I don't know the answer to this, but I can verify by timing in the console that splitting is faster)
I Would be surprised if it was faster, could you post how you came to think it is?
I made this perf quickly and It shows its not faster.
http://jsperf.com/split-performance
Is it possible that the javascript engine you were using has deferred execution capabilities and so the actual splitting didn't occur yet? Try timing again in the console but included accessing the first member of the split array.
精彩评论