for-vs-forEach

Benchmark created on


Setup

const arr = Array.from({ length: 10000 }, (_, i) => i);
const fn = i => i;

Test runner

Ready to run.

Testing in
TestOps/sec
for
for (let i = 0, len = arr.length; i < len; i++) {
	fn();
}
ready
forEach
arr.forEach(fn)
ready
for...of
for (let i of arr) {
	fn();
}
ready

Revisions

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