slice vs length - 1 (v2)

Revision 2 of this benchmark created on


Setup

Array.prototype.get = function(index)
    {
        if(index < 0)
            return this[this.length+index];
        return this[index];
    }
    
    var x = [1,2,3,4,54,1,2,,6,457,4,53,52,34,2,34,45,357,6325,3,5532,423,43,5325,42,542,6,3256,78,569,87,43,2,342,34,6,23,24,'1243']

Test runner

Ready to run.

Testing in
TestOps/sec
slice
var y = x.slice(-1)
ready
length - 1
var y = x[x.length - 1]
ready
custom slice
var y = x.get(-1)
ready

Revisions

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