Array access

Benchmark created on


Setup

let array  = [1,2,3,4,5,6,7,8,9];
let array2 = [1,2,3,4,5,6,7,8,9];

function at(array, idx) {
	let val = array2[idx];
	if( val !== undefined)
	    return val
    // we should make the lazy conversion here
    // but that wouldn't be fair.
	throw 'not implemented'
}


function at2(array, idx) {
	return array2[idx] // if you already use one
}

Test runner

Ready to run.

Testing in
TestOps/sec
for
for(let i = 0; i < array.length; ++i)
 array[i]
ready
at
for(let i = 0; i < array.length; ++i)
 at(array, i);
ready
at2
for(let i = 0; i < array.length; ++i)
 at2(array, i);
ready

Revisions

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