shift-vs-slice-arguments

JavaScript performance comparison

Revision 2 of this test case created by derry

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    shiftArguments = function() {
      Array.prototype.shift.call(arguments);
    }
    shift2Arguments = function() {
      Array.apply(null, arguments).shift();
    }
    sliceArguments = function() {
      Array.prototype.slice.call(arguments, 1);
    }
    slice2Arguments = function() {
      Array.apply(null, arguments).slice(1);
    }
   
    forArguments = function() {
          var args = new Array(arguments.length-1);
          for (var i = 1, l = arguments.length; i < l; i++) {
            args[i-1] = arguments[i];
          }
          return args;
    }
   
};
</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
slice
sliceArguments(1);
pending…
shift
shiftArguments(1);
pending…
slice2
slice2Arguments(1);
pending…
shift2
shift2Arguments(1);
pending…
for
forArguments(1);
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