Last Array Element

JavaScript performance comparison

Revision 11 of this test case created by owns

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  var arr = [];
  var elems = Math.floor(Math.random() * 70 + 5);
  var last;

};
</script>

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
.length-1
// async test
for (var i = 0; i < elems; i++) {
  arr.push(i);
  last = arr[arr.length - 1];
}
pending…
slice(-1)[0]
// async test
for (var i = 0; i < elems; i++) {
  arr.push(i);
  last = arr.slice(-1)[0];
}
pending…
set during push
// async test
for (var i = 0; i < elems; i++) {
  arr.push(last = i);
}
pending…
Control (elems pre-cached)
// async test
for (var i = 0; i < elems; i++) {
  arr.push(i);
  last = arr[i];
}
pending…
Push-Pop
// async test
pending…

Compare results of other browsers

Revisions

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

0 Comments