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
Jump 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
Test name
Executions per second
forEach
99548.1 Ops/sec
filter.map
116689.7 Ops/sec
Related benchmarks:
JS Test 1230
forEach, for, map
Array loop vs foreach vs map vs filter
Array loop vs foreach vs map vs filter vs reduce
Object filtered Array loop vs foreach vs map vs while
Search - forEach vs reduce vs map vs filter vs for
forEach vs filter().map() vs map().filter()
Comments
Confirm delete:
Do you really want to delete benchmark?