array append time metrics simple

JavaScript performance comparison

Revision 2 of this test case created by Eric Burley

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  var a = [],
    b = [],
    c = [],
    i = 0;
  
  // init a 1000 and 5000 and 100,000 element array
  for (; i < 1000; i++) {
    a[i] = i;
  }
  for (i = 0; i < 5000; i++) {
    b[i] = i;
  }
  for (i = 0; i < 100000; i++) {
    c[i] = i;
  }

};

Benchmark.prototype.teardown = function() {
  a = b = c = null;
  i = 0;

};
</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
append elements to a 1000 element array
var x = 0;
for (x = 0; x < 100; x++) {
  a[a.length] = x;
}
for (; x > 0; x--) {
  delete a[a.length - 1];
}
pending…
append elements to the end of a 5000 element array
var x = 0;
for (x = 0; x < 100; x++) {
  b[b.length] = x;
}
for (; x > 0; x--) {
  delete b[b.length - 1];
}
pending…
append and then remove elements from a 5000 element array using push and pop
var x = 0;
for (x = 0; x < 100; x++) {
  a.push(x);
}
for (; x > 0; x--) {
  a.pop();
}
pending…
append and then remove elements from a 1000 element array using push and pop
var x = 0;
for (x = 0; x < 100; x++) {
  b.push(x);
}
for (; x > 0; x--) {
  b.pop();
}
pending…
append and then remove on a 100,000 element array
var x = 0;
for (x = 0; x < 100; x++) {
  c.push(x);
}
for (; x > 0; x--) {
  c.pop();
}
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