es-toolkit/benchmarks/performance/groupBy.bench.ts
2024-07-17 11:47:39 +09:00

30 lines
886 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/groupBy', () => {
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/groupBy', () => {
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);
});
});