GroupBy Lodash vs Native

Benchmark created on


Setup

const data = [];

for (let i = 0; i < 10000; i++)
{
	let foo = "foo";
	if (i < 3000) foo = "boo";
	if (i > 3000 && i < 7000) foo = "moo";
	data.push({id: i, foo: foo});
}

Test runner

Ready to run.

Testing in
TestOps/sec
Lodash GroupBy
const grouped = _.groupBy(data, 'foo');
console.log(grouped);
ready
Native GroupBy
const grouped = {};
for (let i = 0; i < data.length; i++)
{
	if (grouped[data[i].foo]) {
		grouped[data[i].foo].push(data[i].id)	
	} else {
    grouped[data[i].foo] = [data[i].id]
  }
}
console.log(grouped);
ready

Revisions

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