Last Array Element (v5)

Revision 5 of this benchmark created on


Setup

var arr = [];
  var elems = Math.floor(Math.random() * 70 + 5);
  for (var i = 0; i < elems; i++) {
    arr.push(i);
  }

Test runner

Ready to run.

Testing in
TestOps/sec
.length-1
var last = arr[arr.length - 1];
ready
slice(-1)[0]
var last = arr.slice(-1)[0];
ready
Push-Pop
var last = arr.pop();
ready
Control (elems pre-cached)
var last = arr[elems-1];
ready

Revisions

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