Toggle navigation
MeasureThat
.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
forEach vs filter().map()
(version: 0)
Comparing performance of:
forEach vs filter.map
Created:
one year ago
by:
Guest
Go to the latest result
Script Preparation code:
var arr = []; for (var i = 0; i < 1000; i++) { arr[i] = { i, extra: Math.random() < 0.5 ? null : 'test' }; }
Tests:
forEach
var newArr = []; arr.forEach((x) => { if (x.extra !== null) { newArr.push({ ...x, extra: x.extra + '!' }); } });
filter.map
var newArr = arr .filter((x) => x.extra !== null) .map((x) => ({ ...x, extra: x.extra + '!' }));
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
forEach
filter.map
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/129.0.0.0 Safari/537.36
Browser/OS:
Chrome 129 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
filter.map
117K/s
forEach
100K/s
View exact numbers
Test name
Executions per second
✓
filter.map
116,690 Ops/sec
forEach
99,548 Ops/sec
Related benchmarks
Array loop vs foreach vs map vs filter
Array loop vs foreach vs map vs filter vs reduce
forEach vs filter().map() vs map().filter()
Comments
Confirm delete:
Do you really want to delete benchmark?