Emptying an array (v25)

Revision 25 of this benchmark created on


Setup

var arr = [],
    narr;
  if (window.narr) {
    narr = window.narr
  } else {
    narr = [];
    for (var i = 0, len = 25 * 1024 * 1024; i < len; i++) // runs 25 to 100 times = some mb
    {
      narr.push('a' + i);
    }
  }
  arr = narr.slice();

Test runner

Ready to run.

Testing in
TestOps/sec
Setting .length to 0
arr.length = 0;

// setTimeout(function() {}, 1); // give the GC some time to kick in
ready
Creating a new empty array
arr = [];

// setTimeout(function() {}, 1); // give the GC some time to kick in
ready
Splice
arr.splice(0, arr.length);

// setTimeout(function() {}, 1); // give the GC some time to kick in
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.