mirror of
https://github.com/toss/es-toolkit.git
synced 2024-12-01 02:33:54 +03:00
cf65b2c601
* chore: add prettierrc * chore: apply format with prettier config * chore: eslint error fix
30 lines
870 B
TypeScript
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);
|
|
});
|
|
});
|