Holey arrays (v2)

Revision 2 of this benchmark created on


Setup

const ints = [];
const holeyInts = [];
const dictionaryInts = [];
dictionaryInts[999] = true;
for(let i=0; i<1000; i++) {
	ints[i] = i;
	if (i%2) {
		holeyInts[i] = i;
		//dictionaryInts[i] = i;
	}
}

Test runner

Ready to run.

Testing in
TestOps/sec
Sum with no holes
let sum = 0;
for(let i=0; i<ints.length; i++) {
	sum += ints[i];
}
ready
Sum with holes
let sum = 0;
for(let i=0; i<holeyInts.length; i++) {
	sum += holeyInts[i] || 0;
}
ready
Sum of dictionary
let sum = 0;
for(let i=0; i<dictionaryInts.length; i++) {
	sum += dictionaryInts[i] || 0;
}
ready

Revisions

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