Last Array Element (v12)

Revision 12 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-2
var last = arr[arr.length - 2];
ready
slice(-2,-1)[0]
var last = arr.slice(-2,-1)[0];
ready
Push-Pop
var last;
arr.push(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.