Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
If/Push or Map/Filter
(version: 1)
Create a filtred array using forEach/if/push or map/filter
Comparing performance of:
If/Push vs Map/Filter
Created:
one year ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<!--your preparation HTML code goes here-->
Script Preparation code:
var n = Array.from(new Array(10000)).map((value, index) => index);
Tests:
If/Push
var result = []; n.forEach((value) => { if (value % 2) { result.push(value); } });
Map/Filter
var result = n.map((value) => { return value % 2 ? value : 0; }); result = result.filter(value => value !== 0);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
If/Push
Map/Filter
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/135.0.0.0 Safari/537.36
Browser/OS:
Chrome 135 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
If/Push
40624.8 Ops/sec
Map/Filter
5637.1 Ops/sec
Related benchmarks:
for loop push vs mapFilter
filter + map vs conditional + foreach
.map().filter() vs .reduce vs .foreach()
.filter().map() vs .reduce test
Some, Filter, indexOf
Some, Filter, indexOf.
Object filtered Array loop vs foreach vs map vs while
Nj9ZJ^FuK4AJ#wKEww
Search - forEach vs reduce vs map vs filter vs for
Comments
Confirm delete:
Do you really want to delete benchmark?