Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
array operations vs generators vs for loop
(version: 3)
Comparing performance of:
array operations vs generators vs for loop
Created:
one year ago
by:
Registered User
Jump to the latest result
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); }
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
array operations
generators
for loop
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
2 months ago
)
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/OS:
Chrome 144 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
array operations
64.5 Ops/sec
generators
61.0 Ops/sec
for loop
54.8 Ops/sec
Related benchmarks:
for/of vs Array loop vs foreach vs map
generator vs array
traditional for loop vs for ... of
Range vs for of
Performance of JavaScript .forEach, .map and .reduce vs for and for..ofCXCcccc
Array sum with 7 diff loops
Performance of JavaScript .forEach, .map and .reduce vs for and for..of2
range generator vs array
Performance of JS .foreach, for, for...of
Comments
Confirm delete:
Do you really want to delete benchmark?