es-toolkit/benchmarks/groupBy.bench.ts
Minsoo Kim cf65b2c601
style(*): Setup prettier and apply formatting (#24)
* chore: add prettierrc

* chore: apply format with prettier config

* chore: eslint error fix
2024-06-04 17:19:26 +09:00

30 lines
870 B
TypeScript

import { bench, describe } from 'vitest';
import { groupBy as groupByToolkit } from 'es-toolkit';
import { groupBy as groupByLodash } from 'lodash';
describe('groupBy', () => {
bench('es-toolkit', () => {
const array = [
{ category: 'fruit', name: 'apple' },
{ category: 'fruit', name: 'banana' },
{ category: 'vegetable', name: 'carrot' },
{ category: 'fruit', name: 'pear' },
{ category: 'vegetable', name: 'broccoli' },
];
groupByToolkit(array, item => item.category);
});
bench('lodash', () => {
const array = [
{ category: 'fruit', name: 'apple' },
{ category: 'fruit', name: 'banana' },
{ category: 'vegetable', name: 'carrot' },
{ category: 'fruit', name: 'pear' },
{ category: 'vegetable', name: 'broccoli' },
];
groupByLodash(array, item => item.category);
});
});