Lodash GroupBy

Benchmark created on


Description

Native groupby vs lodash groupBy

Setup

const data = [];

for (let i = 0; i < 10000; i++)
{
	let foo = "foo";
	if (i < 300) foo = "boo";
	if (i > 300 && i < 700) 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[id].id)	
	} 
}
console.log(grouped);
ready

Revisions

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