mirror of
https://github.com/toss/es-toolkit.git
synced 2024-11-28 20:26:33 +03:00
30 lines
759 B
TypeScript
30 lines
759 B
TypeScript
import { bench, describe } from 'vitest';
|
|
import { flatMap as flatMapToolkit } from 'es-toolkit';
|
|
import { flatMapDepth as flatMapDepthLodash } from 'lodash';
|
|
|
|
function createNestedArray(arr: any[], depth: number) {
|
|
let result = arr;
|
|
|
|
for (let i = 0; i < depth; i++) {
|
|
result = [result];
|
|
}
|
|
return result;
|
|
}
|
|
|
|
describe('flatMap', () => {
|
|
const iterateeDepth = (item: number) => createNestedArray([item, item, item], 10);
|
|
const arr = Array.from({ length: 30 }, (_, i) => i);
|
|
|
|
bench('es-toolkit/flatMap', () => {
|
|
flatMapToolkit(arr, iterateeDepth, 10);
|
|
});
|
|
|
|
bench('lodash/flatMapDepth', () => {
|
|
flatMapDepthLodash(arr, iterateeDepth, 10);
|
|
});
|
|
|
|
bench('js built-in/map.flat', () => {
|
|
arr.map(iterateeDepth).flat(10);
|
|
});
|
|
});
|