Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
`filter().length` vs. `reduce` 2
(version: 1)
Compare `filter().length` vs `reduce` vs `for` loop for counting array elements that are present in another array.
Comparing performance of:
filter().length vs reduce vs for loop
Created:
one year ago
by:
Guest
Jump to the latest result
Script Preparation code:
var sample = Array(10000).fill(0).map((_, idx) => idx); var selected = [10, 134, 245, 355, 489, 583, 682, 823, 2081, 3892, 4892, 5829, 6832];
Tests:
filter().length
var total = selected.filter(id => sample.includes(id)).length;
reduce
var total = selected.reduce((total, id) => sample.includes(id) ? total + 1 : total, 0);
for loop
var total = 0; for (const id of selected) { if (sample.includes(id)) { total++; } }
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
filter().length
reduce
for loop
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/135.0.0.0 Safari/537.36
Browser/OS:
Chrome 135 on Linux
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
filter().length
633012.5 Ops/sec
reduce
648380.8 Ops/sec
for loop
644809.5 Ops/sec
Related benchmarks:
.map().filter() vs .reduce vs .foreach()
.filter().map() vs .reduce test
reduce vs filter+map
`filter().length` vs. `reduce` vs. `for`
`filter().length` vs. `reduce` vs. `for` (with Set)
Filter and Map vs Reduce
Array.find vs Array.filter on large dataset
`filter().length` vs. `reduce` vs. `for` fork
`filter().length` vs. `reduce`
Comments
Confirm delete:
Do you really want to delete benchmark?