Array::append variants

Benchmark created by denim2x on


Description

Compares different variants of Array.prototype.append.

Setup

this.array = [];
    for (var i = 1e3-1; i >= 0; --i) {
      this.array[i] = i;
    }
    
    var push = Array.prototype.push;
    Array.prototype.append = function (array) {
      push.apply(this, array);
      return this;
    };
    Array.prototype.append2 = function (array) {
      var size = array.length;
      for (var i = 0; i < size; i++) this.push(array[i]);
      return this;
    };

Test runner

Ready to run.

Testing in
TestOps/sec
push.apply
[].append(this.array);
ready
for loop
[].append2(this.array);
ready

Revisions

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

  • Revision 1: published by denim2x on
  • Revision 2: published by denim2x on