Simple array append comparison

JavaScript performance comparison

Test case created by T.J. Crowder

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  var check1 = Math.floor(Math.random() * 500);
  var check2 = Math.floor(Math.random() * 500);
  var check3 = Math.floor(Math.random() * 500);
  function check(a) {
    if (a[check1] != check1 * 2 ||
        a[check2] != check2 * 2 ||
        a[check3] != check3 * 2) {
      throw new Error("Error in test");
    }
  }

};
</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
push
var array = [];
var i;
for (i = 0; i < 500; ++i) {
  array.push(i * 2);
}
check(array);
pending…
assignment
var array = [];
var i;
for (i = 0; i < 500; ++i) {
    array[array.length] = i * 2;
}
check(array);
pending…

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

0 Comments