Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
For vs For Of vs Filter+Map vs FlatMap
(version: 1)
Comparing performance of:
For vs For Of vs Filter+Map vs FlatMap
Created:
one year ago
by:
Guest
Jump to the latest result
Script Preparation code:
var data = [] for (let i = 0; i < 1000; i++) { data.push(i); }
Tests:
For
const result = [] for (let i = 0; i < data.length; i++) { if (data[i] % 2 == 0) { result.push(data[i]*2); } }
For Of
const result = [] for (const x of data) { if (x % 2 == 0) { result.push(x*2); } }
Filter+Map
const result = data.filter((x) => x % 2 == 0).map((x) => x*2);
FlatMap
const result = data.filter((x) => x % 2 == 0 ? x*2 : []);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (4)
Previous results
Fork
Test case name
Result
For
For Of
Filter+Map
FlatMap
Fastest:
N/A
Slowest:
N/A
Latest run results:
No previous run results
This benchmark does not have any results yet. Be the first one
to run it!
Comments
Confirm delete:
Do you really want to delete benchmark?