News for hackers. Stuff that matters.
Re:Google Closure: How not to write JavaScript by axod on Monday December 13, 2010 @04:53AM (#1999979)
http://axod.net/arraytest.html

  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<arr.length;i++) is it can end up as an infinite loop if you're modifying the length inside the for loop:

  for (var i=0;i<arr.length;i++) {
    arr[10 + i*2] = "foo";
  }

  // Infinite loop.
Re:Google Closure: How not to write JavaScript by gruseom on Monday December 13, 2010 @12:18PM (#2001137)
Perhaps you were seeing GC events slowing down the test?

Perhaps. Or perhaps it varies by array size?

Re:Google Closure: How not to write JavaScript by bluekeybox on Monday December 13, 2010 @12:43PM (#2001272)
Then do not write code like this.