slice vs length

Benchmark created on


Preparation HTML

<script>
  var array = [], i;
  for (i = 0; i < 100000; i++) {
    array.push('item' + i);
  }
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
slice
var lastItem = array.slice(-1)[0];
ready
length
var lastItem = array[array.length-1];
ready
slice and pop
var lastItem = array.slice().pop();
ready
pop and push
var lastItem;
array.push(lastItem = array.pop());
ready

Revisions

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