slice vs length - 1 vs custom (v11)

Revision 11 of this benchmark created on


Preparation HTML

<script>

Object.defineProperty( Array.prototype, "getLast", {
    enumerable: false,
    configurable: false,
    writable: false,
    value: function() {
        return this[ this.length - 1 ];
    }
} );

</script>

Setup

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
var y = x.getLast()
ready

Revisions

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