cr-52768 (v6)

Revision 6 of this benchmark created by Justin Ridgewell on


Preparation HTML

<script src="https://rawgit.com/megawac/underscore/slice/underscore.js"></script>

Setup

var set = _.range(30);
    
    var holedset = Array(30);
    for (var i = 0; i < 5; i++) {
        holedset[i * 6] = i;
    }
    
    function protoSlice(set, i) {
        return set.slice(i);
    };
    
    var slice = Array.prototype.slice;
    function callSlice(set, i) {
        return slice.call(set, i);
    }
    
    _.simpleSlice = function(collection, start, end) {
        var length = collection.length;
    
        if (start == null || !+start) start = 0;
        else if (start < 0) start += -start > length ? -start : length;
    
        if (end == null || end > length) end = length;
        else if (!+end) end = 0;
        else if (end < 0) end += length;
    
        length = end < start ? 0 : end - start;
        var result = Array(length);
        for (var i = 0; i < length; i++)  result[i] = collection[i + start];
        return result;
    };

Test runner

Ready to run.

Testing in
TestOps/sec
slice (prototype)
protoSlice(set, 1);
ready
slice (call)
callSlice(set, 1);
ready
slice (megawac)
_.slice(set, 1);
ready
slice (simple)
_.simpleSlice(set, 1);
ready
slice (holes, prototype)
protoSlice(holedset, 1);
ready
slice (holes, call)
callSlice(holedset, 1);
ready
slice (holes, megawac)
_.slice(holedset, 1);
ready
slice (holes, simple)
_.simpleSlice(holedset, 1);
ready

Revisions

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

  • Revision 6: published by Justin Ridgewell on