Array.prototype.slice.call() vs [].slice.call()

JavaScript performance comparison

Revision 30 of this test case created by Fidel90

Preparation code

<script>
  var items = [1, 2, 3, 4, 5],
      slice = Array.prototype.slice;
</script>
    

Test runner

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

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
Array.prototype.slice
var arr = Array.prototype.slice.call(items);
pending…
[].slice
var arr = [].slice.call(items);
pending…
cached prototype
var arr = slice.call(items);
pending…
Instance method
var arr = items.slice();
pending…
elementwise copy
var length = items.lenght, i = 0, arr = new Array(length);

for (i; i<length; i+=1) {
    arr[i] = items[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.

0 Comments