Empty array

JavaScript performance comparison

Revision 89 of this test case created by

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  var i;
  var arr = [];
  var arr2 = [1];
  for (i=0; i<10000; i++)
    arr.push({a: 1, b: "2"});
  
  for (i=1; i<10000; i++)
    arr2.push(1);
  

};
</script>

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
length
arr.length = 0;
pending…
splice
arr.splice(0, arr.length);
pending…
pop
while (arr.length > 0) {
  arr.pop();
}
pending…
shift
while (arr.length > 0) {
  arr.shift();
}
pending…
new array
arr = [];
pending…
length 2
arr2.length = 0;
pending…
splice 2
arr2.splice(0, arr2.length);
pending…
pop 2
while (arr2.length > 0) {
  arr2.pop();
}
pending…
shift 2
while (arr2.length > 0) {
  arr2.shift();
}
pending…
new array 2
arr2 = []
pending…
Pop and test
while (arr.length > 0) {
  arr.pop();
}
if (arr.length !== 0) alert("oops!");
pending…

Compare results of other browsers

Revisions

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

0 Comments