slice native vs manual

JavaScript performance comparison

Test case created by shwups

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    var args = null;
    !function(){
      args = arguments
    }(1,2,3,4,4,5,6,7,8,9);
   
   
    sliced = function (args, slice, sliceEnd) {
      var ret = [];
      var len = args.length;
      if (0 === len) return ret;
      var start = slice < 0
        ? Math.max(0, slice + len)
        : slice || 0;
      if (sliceEnd !== undefined) {
        len = sliceEnd < 0
          ? sliceEnd + len
          : sliceEnd
      }
      while (len-- > start) {
        ret[len - start] = args[len];
      }
      return ret;
    }
    manual = { slice:sliced }
   
    nativeSlice = Array.prototype.slice;
};
</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
manual
x = manual.slice(arguments)
pending…
native
x = nativeSlice.call(arguments)
pending…

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

Compare results of other browsers

0 comments

Add a comment