push vs custom push

JavaScript performance comparison

Test case created by Xotic750

Preparation code

<script>
  var a = [],
      c = 1000,
      i;

  function customPush(array, value) {
    array[array.length] = value;
  }

  Array.prototype.customPush = function(value) {
    this[this] = value;
  }
</script>

Test runner

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

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
native
for (i = 0, a.length = 0; i < c; i += 1) {
  a.push(i);
}
pending…
custom
for (i = 0, a.length = 0; i < c; i += 1) {
  customPush(a, i);
}
pending…
functionless
for (i = 0, a.length = 0; i < c; i += 1) {
  a[a.length] = i
}
pending…
custom prototype
for (i = 0, a.length = 0; i < c; i += 1) {
  a.customPush(i);
}
pending…
assigned
for (i = 0, a.length = 0; i < c; i += 1) {
  a[i] = i;
}
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. Here’s a list of current revisions for this page:

0 comments

Add a comment