_.groupBy Vs Filter

Benchmark created on


Preparation HTML

<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.21/lodash.min.js">

Setup

const arr1 = new Array(100).fill(0).map((_, i) => ({foo: 'hey' + i, bar: Math.random() }))
const arr2 = new Array(100).fill(0).map((_, i) => ({foo: undefined, bar: Math.random() }))

const arr3 = arr1.concat(arr2)

Test runner

Ready to run.

Testing in
TestOps/sec
groupBy
const {true: hasIt, false: doesNot} = _.groupBy(arr3, (item) => !!item.foo)
ready
filter
const hasIt = arr3.filter((item) => !!item.foo)
const doesNot = arr3.filter((item) => !item.foo)
ready

Revisions

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