Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
`filter().length` vs. `reduce` 2
Compare `filter().length` vs `reduce` vs `for` loop for counting array elements that are present in another array.
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:138.0) Gecko/20100101 Firefox/138.0
Browser:
Firefox 138
Operating system:
Windows
Device Platform:
Desktop
Date tested:
one year ago
Test name
Executions per second
filter().length
19614.7 Ops/sec
reduce
19774.8 Ops/sec
for loop
19389.2 Ops/sec
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++; } }