Object.groupBy vs forEach

Benchmark created on


Setup

const arr = new Array(100000).fill(0).map(e => Math.random())

Test runner

Ready to run.

Testing in
TestOps/sec
Object.groupBy
const arr1 = Object.groupBy(arr, e => (e * 10).toFixed(2).toString())
ready
forEach
const arr2 = {}

arr.forEach(e => {
	const key = (e * 10).toFixed(2).toString();
	arr2[key] ??= [];
	arr2[key].push(e);
})
ready

Revisions

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