Creating a new array vs Emptying an array

Edit on GitHub

Setup

Tests

  • Creating a new array

    var foo = [];
    for (var j = 0; j < 1000; ++j) {
      foo = [];
    for (var i = 0; i < 1000; ++i) {
      foo.push(10);
    }
    }
  • Emptying an array

    var foo = [];
    for (var j = 0; j < 1000; ++j) {
      foo.length = 0;
    for (var i = 0; i < 1000; ++i) {
      foo.push(10);
    }
    }