Array VS Iterrator (v11)

Revision 11 of this benchmark created on


Setup

function generateData(size) {
    return Array.from({ length: size }, (_, i) => i);
}

const arr = generateData(100000);
const TAKE_NO = Math.floor(Math.random() * 50000)+4900000;
const DROP_NO = Math.floor(Math.random() * 1000);

Teardown

// console.log(arr_res.length == iter_res.length ? 'CORRECT' : 'UNEQUAL DATA PASSED')

Test runner

Ready to run.

Testing in
TestOps/sec
Array
const arr_res = arr.slice(10, 90010).filter(x=> x>0).map(x=> x+1).filter(x => x< 100000).map(el => el + 5).filter(x => x<100).map(x=> x-1)
ready
Iterrator
const iter_res = arr.values().drop(10).take(90000).filter(x=> x>0).map(x=>x+1).filter(x => x< 100000).map(el => el + 5).filter(x => x<100).map(x=> x-1).toArray()
ready
for loop
const res = [];
for (let i=0; i< arr.length; i++){
	if (i<10) continue;
	if (i>90010) break;
	let x = arr[i];
	if(x<0) continue;
	x +=1;
	if(x>100000) continue;
	x +=5
	if (x<100) {
		res.push(x-1);
	}
}
ready

Revisions

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