Arrays are slow

Benchmark created on


Description

Comparing for(;;) to for..of to Array.forEach

Setup

let 
	test = [],
	extraData = "Something to make the dataset larger;"
for (let value = 0; value < 1000; value++) {
	test[value] = { value, extraData };
}

Test runner

Ready to run.

Testing in
TestOps/sec
old school "for" loop
for (let i = 0, iLen = test.length; i < iLen; i++) {
	test[i].value++;
}
ready
For..of
for (let item of test) {
	item.value++;
}
ready
Array.forEach
test.forEach( (item) => item.value++ );
ready
For only?
for (
	let i = 0, iLen = test.length;
	i < iLen;
	test[i++].value++
);
ready

Revisions

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