Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
array operations vs generators vs for loop
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36
Browser:
Chrome 144
Operating system:
Windows
Device Platform:
Desktop
Date tested:
2 months ago
Test name
Executions per second
array operations
64.5 Ops/sec
generators
61.0 Ops/sec
for loop
54.8 Ops/sec
Script Preparation code:
const array = Array.from({ length: 10_000 }, (_, i) => i);
Tests:
array operations
array .filter((el) => el % 2) .map((el) => el ** 2) .forEach((el) => console.log(el));
generators
function* filterOddIt(it) { for (const el of it) if (el % 2) yield el; } function* squareIt(it) { for (const el of it) yield el ** 2; } function printIt(it) { for (const el of it) console.log(el); } printIt(squareIt(filterOddIt(array)));
for loop
const result = []; for (const el of array) { if (el % 2 == 0) continue; const r = el ** 2; result.push(r); console.log(r); }