开发者

Javascript Split Performance

开发者 https://www.devze.com 2023-04-07 09:35 出处:网络
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:

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消