Ternary spread vs Conditional push

Benchmark created on


Setup

const array = Array.from(Array(1000).keys())
const id = Math.floor(Math.random() * array.length)

Test runner

Ready to run.

Testing in
TestOps/sec
Spread
array.reduce((a, i) => i != id ?  [...a, i] : a, [])
ready
Push
array.reduce((a, i) => {if (i != id) a.push(i); return a}, [])
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.