mirror of
https://github.com/toss/es-toolkit.git
synced 2024-12-01 10:45:08 +03:00
30 lines
886 B
TypeScript
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);
|
|
});
|
|
});
|