Converting arguments to an array (v3)

Revision 3 of this benchmark created on


Preparation HTML

<script>
  function arrayProtoSlice() {
      return Array.prototype.slice.apply(arguments);
  }
  function arrayLiteralSlice() {
      return [].slice.apply(arguments);
  }
  function splice() {
      return [].splice.call(arguments, 0);
  }
  function push() {
      var x = [];
      x.push.apply(x, arguments);
      return x;
  }
  function unshift() {
      var x = [];
      x.unshift.apply(x, arguments);
      return x;
  }
  var smallArray = ((new Array(10)).join("a,") + "a").split(",");
  var mediumArray = ((new Array(100)).join("a,") + "a").split(",");
  var bigArray = ((new Array(1000)).join("a,") + "a").split(",");
  
  unshift.apply(null, bigArray).length === bigArray.length || alert('unshift broken');
  push.apply(null, bigArray).length === bigArray.length || alert('push broken');
  splice.apply(null, bigArray).length === bigArray.length || alert('splice broken');
  arrayProtoSlice.apply(null, bigArray).length === bigArray.length || alert('arrayProtoSlice broken');
  arrayLiteralSlice.apply(null, bigArray).length === bigArray.length || alert('arrayLiteralSlice broken');
  
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
[small] Array prototype slice
arrayProtoSlice.apply(null, smallArray);
ready
[small] Array literal slice
arrayLiteralSlice.apply(null, smallArray);
ready
[small] Array push
push.apply(null, smallArray);
ready
[small] Array splice
splice.apply(null, smallArray);
ready
[small] Unshift
unshift.apply(null, smallArray);
ready
[medium] Array prototype slice
arrayProtoSlice.apply(null, mediumArray);
ready
[medium] Array literal slice
arrayLiteralSlice.apply(null, mediumArray);
ready
[medium] Array push
push.apply(null, mediumArray);
ready
[medium] Array splice
splice.apply(null, mediumArray);
ready
[medium] Unshift
unshift.apply(null, mediumArray);
ready
[big] Array prototype slice
arrayProtoSlice.apply(null, bigArray);
ready
[big] Array literal slice
arrayLiteralSlice.apply(null, bigArray);
ready
[big] Array push
push.apply(null, bigArray);
ready
[big] Array splice
splice.apply(null, bigArray);
ready
[big] Unshift
unshift.apply(null, bigArray);
ready

Revisions

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