Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
filter.foreach vs foreach with condition
(version: 1)
Comparing performance of:
forEach vs filter
Created:
one year ago
by:
Guest
Jump to the latest result
Script Preparation code:
var arr = []; for (var i = 0; i < 12345; i++) { arr[i] = i; } var sumForEach = 0, sumFilter = 0;
Tests:
forEach
arr.forEach((item) =>{if(item%2 == 0){ sumForEach++; }});
filter
arr.filter((item) => item%2 == 0).forEach((item) => { sumFilter++; });
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
forEach
filter
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
9 months ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:140.0) Gecko/20100101 Firefox/140.0
Browser/OS:
Firefox 140 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
forEach
7717.5 Ops/sec
filter
6149.4 Ops/sec
Related benchmarks:
forEach vs reduce vs map vs filter vs for (better for)
forEach vs reduce vs map vs filter vs for2
forEach vs reduce vs map vs filter vs for -- exlord
forEach vs reduce vs map vs filter vs for (v2)
forEach vs reduce vs map vs filter vs for vs for...of
forEach vs reduce vs map vs filter vs for vs for..of
filter + forEach vs forEach + guard
forEach vs filter vs for
forEach vs for-of vs reduce vs map vs filter vs for
Comments
Confirm delete:
Do you really want to delete benchmark?