Open D-Sketon opened 5 hours ago
The same issue arises when calling with the subpath as shown below, resulting in a performance difference.
import { bench, describe } from 'vitest';
import { after as afterToolkit } from 'es-toolkit'; // This is difference.
import { after as afterLodash } from 'lodash';
describe('after', () => {
bench('es-toolkit/after', () => {
const add = (a: number, b: number) => a + b;
const n = 10;
const afterFn = afterToolkit(n, add);
for (let i = 0; i < n + 1; i++) {
afterFn(1, 2);
}
});
bench('lodash/after', () => {
const add = (a: number, b: number) => a + b;
const n = 10;
const afterFn = afterLodash(n, add);
for (let i = 0; i < n + 1; i++) {
afterFn(1, 2);
}
});
});
import { bench, describe } from 'vitest';
import { after as afterToolkit } from 'es-toolkit/function'; // This is difference.
import { after as afterLodash } from 'lodash';
describe('after', () => {
bench('es-toolkit/after', () => {
const add = (a: number, b: number) => a + b;
const n = 10;
const afterFn = afterToolkit(n, add);
for (let i = 0; i < n + 1; i++) {
afterFn(1, 2);
}
});
bench('lodash/after', () => {
const add = (a: number, b: number) => a + b;
const n = 10;
const afterFn = afterLodash(n, add);
for (let i = 0; i < n + 1; i++) {
afterFn(1, 2);
}
});
});
You can see our barrel files in here(src/index.ts, src/function/index.ts).
Thanks
Describe the bug
I try the following code and run
vitest bench
Here's what I got:
You can see that a direct import statement using import is significantly slower than reassigning values However, when I try tinybench like this:
There is no difference between them:
Reproduction
Use the code above
System Info
Used Package Manager
yarn
Validations