Array - access last and add new

Benchmark created on


Description

Access last value and add new value to array

Test runner

Ready to run.

Testing in
TestOps/sec
Destructured array ES6
let arr = [], i = 10000;

while(i){
	i--;
	let [last] = arr.slice(-1);
	let newEntry = (last || 0 ) + i;
	arr.push(newEntry);
}
ready
Test length
let arr = [], i = 10000;

while(i){
	i--;
	let [last] = arr.slice(-1);
	let length = arr.length;
	let newEntry = (length ? arr[length-1] : 0 ) + i;
	arr.push(newEntry);
}
ready
Get last
let arr = [], i = 10000;

while(i){
	i--;
	let last = arr[arr.length-1];
	let newEntry = (last || 0 ) + i;
	arr.push(newEntry);
}
ready

Revisions

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