Last Array Element (v11)

Revision 11 of this benchmark created by owns on


Setup

var arr = [];
  var elems = Math.floor(Math.random() * 70 + 5);
  var last;

Test runner

Ready to run.

Testing in
TestOps/sec
.length-1
// async test
for (var i = 0; i < elems; i++) {
  arr.push(i);
  last = arr[arr.length - 1];
}
ready
slice(-1)[0]
// async test
for (var i = 0; i < elems; i++) {
  arr.push(i);
  last = arr.slice(-1)[0];
}
ready
set during push
// async test
for (var i = 0; i < elems; i++) {
  arr.push(last = i);
}
ready
Control (elems pre-cached)
// async test
for (var i = 0; i < elems; i++) {
  arr.push(i);
  last = arr[i];
}
ready
Push-Pop
// async test
ready

Revisions

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