Array access (v5)

Revision 5 of this benchmark created on


Setup

let array  = Array.from({length: 10000}, (_e, i) => i); // big number to prevents browser cache
let array2 = array.map( e => { return {obj: e} });

let array3 = new Array(array.length).fill( (i) => array[i] )

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


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

function update(_array, _i) {
	
	throw new Error('Not implemented !')
	}

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
lambda
for(let i = 0; i < array.length; ++i)
 array3[i]?.(i) ?? update(array3, i); // reuse the lamba to gain perf on construction
ready
for at
for(let i = 0; i < array.length; ++i)
 array.at(i)
ready

Revisions

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