forEach/push vs filter/map (v2)

Revision 2 of this benchmark created on


Setup

const initialValues = [
{code: "yo",value: 5},
{code: "yo1",value: undefined},
{code: "yo2",value: 5},
{code: "yo3",value: 5},
{code: "yo4",value: undefined},
{code: "yo5",value: 5},
{code: "yo6",value: 5},
{code: "yo7",value: 5},
{code: "yo8",value: 5},
{code: "yo9",value: 5},
{code: "yo10",value: undefined},
{code: "yo11",value: 5},
{code: "yo12",value: 5},
]

Test runner

Ready to run.

Testing in
TestOps/sec
forEach/push
const relatedConditions = []
initialValues.forEach((e) => {
   if (e.value) {
      relatedConditions.push(e.code)
   }
})
ready
filter/map
const relatedConditions = initialValues.filter(e => e.value).map(e => e.code)
ready

Revisions

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