Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Reduce vs Loop (partition) 1000
(version: 0)
Comparing performance of:
Reduce vs Regular loop vs Of loop vs Of loop (let not const)
Created:
3 years ago
by:
Registered User
Jump to the latest result
Script Preparation code:
arr = [...Array(1000)].map((v, i) => (i + 1)) filter = (el) => el % 2 === 0
Tests:
Reduce
arr.reduce( ([pass, fail], elem) => { if (filter(elem)) { return [[...pass, elem], fail]; } else { return [pass, [...fail, elem]]; } }, [[], []], );
Regular loop
const pass = []; const fail = []; for (let i = 0; i < arr.length; i++) { if (filter(arr[i])) { pass.push(arr[i]); } else { fail.push(arr[i]); } }
Of loop
const pass = []; const fail = []; for (const item of arr) { if (filter(item)) { pass.push(item); } else { fail.push(item); } }
Of loop (let not const)
const pass = []; const fail = []; for (let item of arr) { if (filter(item)) { pass.push(item); } else { fail.push(item); } }
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (4)
Previous results
Fork
Test case name
Result
Reduce
Regular loop
Of loop
Of loop (let not const)
Fastest:
N/A
Slowest:
N/A
Latest run results:
No previous run results
This benchmark does not have any results yet. Be the first one
to run it!
Related benchmarks:
Array iteration_0001
reduce vs map/filter --- filter and reshape
Reduce vs Loop (partition)
Flat map + filter vs. Reduce
Comments
Confirm delete:
Do you really want to delete benchmark?