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

Revision 19 of this benchmark created by Victor on


Description

caching the prototype lookup should be fastest... Would it be even faster if we cache the call too...

Preparation HTML

<script>
var slice = Array.prototype.slice,
    _slice = [].slice,
    wslice = window.Array.prototype.slice;

var items = new Array(100);
for (var i = 0; i < 100; i++) {
    items[i] = i;
}

function nonnative_slice(item, start) {
    start = ~~start;
    var len = item.length, newArray = new Array(len - start);
    for (var i = start; i < len; i++) {
        newArray[i - start] = item[i];
    }
    return newArray;
}
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
Array.prototype.slice
Array.prototype.slice.call(items)
ready
[].slice
[].slice.call(items)
ready
cached prototype
slice.call(items);
ready
cached [].slice
_slice.call(items);
ready
Array().slice
Array().slice.call(items);
ready
window.Array
window.Array.prototype.slice.call(items);
ready
wslice cached
wslice.call(items);
ready
slice(0)
items.slice(0)
ready
non native slice
nonnative_slice(items);
ready

Revisions

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