Empty JavaScript array redux

JavaScript performance comparison

Test case created by diadistis

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  var small = [],
      medium = [],
      big = [],
      smallSize = 100,
      mediumSize = 10000,
      bigSize = 100000;
  
  while (smallSize--) {
      small.push(Math.random());
  }
  
  while (mediumSize--) {
      medium.push(Math.random());
  }
  
  while (bigSize--) {
      big.push(Math.random());
  }

};
</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 = 0 (big)
var arr = big.slice();
arr.length = 0;
pending…
splice (small)
var arr = small.slice();
arr.splice(0, arr.length);
pending…
splice (medium)
var arr = medium.slice();
arr.splice(0, arr.length);
pending…
splice (big)
var arr = big.slice();
arr.splice(0, arr.length);
pending…
while;pop (small)
var arr = small.slice();
while(arr.length > 0) {
    arr.pop();
}
pending…
while;pop (medium)
var arr = medium.slice();
while(arr.length > 0) {
    arr.pop();
}
pending…
while;pop (big)
var arr = big.slice();
while(arr.length > 0) {
    arr.pop();
}
pending…
control (small)
small.slice();
pending…
control (medium)
medium.slice();
pending…
control (big)
big.slice();
pending…
new array (small)
var arr = small.slice();
arr = [];
pending…
new array (medium)
var arr = medium.slice();
arr = [];
pending…
new array (big)
var arr = big.slice();
arr = [];
pending…
length = 0 (small)
var arr = small.slice();
arr.length = 0;
pending…
length = 0 (medium)
var arr = medium.slice();
arr.length = 0;
pending…

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

Compare results of other browsers

0 Comments