es-toolkit/benchmarks/uniqWith.bench.ts
Jun 3cc1a03519
chore(*): Add codspeed for benchmark visualization (#75)
* chore: add codspeed

* chore: fix the benchmark file to clearly distinguish between the comparison targets

* chore: fix typo
2024-06-18 10:40:07 +09:00

28 lines
842 B
TypeScript

import { bench, describe } from 'vitest';
import { uniqWith as uniqWithToolkit } from 'es-toolkit';
import { uniqWith as uniqWithLodash } from 'lodash';
import { randomInt } from 'crypto';
describe('uniqWith, small arrays', () => {
bench('es-toolkit/uniqWith', () => {
uniqWithToolkit([2.1, 1.2, 2.3], (x, y) => Math.floor(x) === Math.floor(y));
});
bench('lodash/uniqWith', () => {
uniqWithLodash([2.1, 1.2, 2.3], (x, y) => Math.floor(x) === Math.floor(y));
});
});
describe('uniqWith, large arrays', () => {
const array = Array.from({ length: 10000 }).map(() => randomInt(0, 10000));
const comparator = (x, y) => Math.floor(x) === Math.floor(y);
bench('es-toolkit/uniqWith', () => {
uniqWithToolkit(array, comparator);
});
bench('lodash/uniqWith', () => {
uniqWithLodash(array, comparator);
});
});