The article says: Although it is necessary in Java, it is entirely pointless to specify the length of an array ahead of time in JavaScript. [...] Rather, you can just set up an empty array and allow it to grow as you fill it in. Not only is the code shorter, but it runs faster too. Faster? That ought to raise suspicion. JS's dynamic hash-arrays are neat, but now they're supposed to be immune from the laws that govern…
After 20 iterations:
Browser Pre-alloc No pre-alloc
Firefox 3.6.13 OSX 824ms 829ms
Safari 5.0.3 OSX 812ms 948ms
Chrome 9.0.597.16 OSX 1317ms 992ms
I'm pretty sure that in modern browsers new Array(length) doesn't allocate anything, it just sets the length property. The results I'm seeing would agree with Google really.Perhaps you were seeing GC events slowing down the test?
The other thing about for(var i=0;i
for (var i=0;i