Toggle navigation
MeasureThat
.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
FlatMap method vs for loop 31-10-24
(version: 0)
Compare the performance of for loop vs flatMap method
Comparing performance of:
flatMap vs for loop
Created:
one year ago
by:
Guest
Go to the latest result
Script Preparation code:
var arr = Array(10_000).fill(0);
Tests:
flatMap
arr.flatMap(x => [x, x * 2]);
for loop
const n = arr.length; const acc = new Array(n * 2); for (let i = 0; i < n; i++){ const x = arr[i]; acc[i * 2] = x; acc[i * 2 + 1] = x * 2; }
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
flatMap
for loop
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
9 months ago
)
User agent:
Mozilla/5.0 (iPhone; CPU iPhone OS 18_6_2 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) CriOS/141.0.7390.96 Mobile/15E148 Safari/604.1
Browser/OS:
Chrome Mobile iOS 141 on iOS 18.6.2
View result in a separate tab
Embed
Embed Benchmark Result
for loop
62K/s
flatMap
13K/s
View exact numbers
Test name
Executions per second
✓
for loop
61,604 Ops/sec
flatMap
13,302 Ops/sec
Related benchmarks
flatMap() vs filter().map() vs for loop accumulator
FlatMap method vs for loop
for-noop vs flatMap
flatMap() vs filter().map() vs for loop accumulator vs forEach
flatMap vs reduce with spread vs reduce with push vs for of
FlatMap method vs for loop big 31-10-24
Comments
Confirm delete:
Do you really want to delete benchmark?