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

30 lines
740 B
TypeScript

import { bench, describe } from 'vitest';
import { keyBy as keyByToolkit } from 'es-toolkit';
import { keyBy as keyByLodash } from 'lodash';
describe('keyBy', () => {
bench('es-toolkit/keyBy', () => {
const people = [
{ name: 'mike', age: 20 },
{ name: 'jake', age: 30 },
{ name: 'john', age: 25 },
{ name: 'sarah', age: 25 },
{ name: 'emma', age: 25 },
];
keyByToolkit(people, person => person.name);
});
bench('lodash/keyBy', () => {
const people = [
{ name: 'mike', age: 20 },
{ name: 'jake', age: 30 },
{ name: 'john', age: 25 },
{ name: 'sarah', age: 25 },
{ name: 'emma', age: 25 },
];
keyByLodash(people, person => person.name);
});
});