es-toolkit/benchmarks/performance/findIndex.bench.ts
2024-08-11 21:03:13 +09:00

25 lines
727 B
TypeScript

import { bench, describe } from 'vitest';
import { findIndex as findIndexToolkit } from 'es-toolkit/compat';
import { findIndex as findIndexLodash } from 'lodash';
const items = [
{ id: 1, name: 'Alice' },
{ id: 2, name: 'Bob' },
];
describe('findIndex', () => {
bench('es-toolkit/compat/findIndex', () => {
findIndexToolkit(items, x => x.name === 'Bob');
findIndexToolkit(items, { name: 'Bob' });
findIndexToolkit(items, ['name', 'Bob']);
findIndexToolkit(items, 'name');
});
bench('lodash/findIndex', () => {
findIndexLodash(items, x => x.name === 'Bob');
findIndexLodash(items, { name: 'Bob' });
findIndexLodash(items, ['name', 'Bob']);
findIndexLodash(items, 'name');
});
});