array slice vs copy

JavaScript performance comparison

Test case created

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    arr = {};
    for(var i = 0; i < 5; ++i) {
        arr[i] = 'derp';
    }
    arr.length = 5;
};
</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
Array slice
var args = Array.prototype.slice.call(arr, 1);
pending…
Copy
var len = arr.length;
var args = new Array(len - 1);
for (i = 1; i < len; i++)
    args[i - 1] = arr[i];
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