for-loop-benchmark

Benchmark created on


Setup

const data = Array
	.from({ length: 100000 })
	.map((o, i) => ({ type: "item", num: i }));

Test runner

Ready to run.

Testing in
TestOps/sec
for loop, long form
for (let i = 0; i < data.length; i++) {
	data[i].type === "item";
}
ready
for each
data.forEach((o, i) => o.type === "item");
ready
for of
for (let item of data) {
	item.type === "item";
}
ready
map
data.map((o, i) => o.type === "item");
ready
filter
data.filter((o, i) => o.type === "item");
ready
find
data.find((o, i) => o.type === "foobar");
ready

Revisions

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