es-toolkit
es-toolkit copied to clipboard
bench: change the benchmark tool from `vitest` to `tinybench`
Description
Vitest introduces overhead from vite, which significantly impacts functions in utility tools with low computation, making it unsuitable for es-toolkit.
To address this, I implemented benchmarking using only tinybench. The process works as follows:
- When a user executes a command, the
bench-runner.mjsscript is triggered. - This script compares the input file with files located in
benchmarks/performanceto determine which files to benchmark. - The selected benchmark files are bundled with
rollupand stored in the.bench-bundlefolder. - The bundled files are then executed using
node <built-file>. - This is repeated for all relevant files.
Additionally, to maintain the usability of vitest, I implemented the same describe and bench interface in the benchmark/bench.ts file.
The main differences are that, instead of importing fromvitest, the functions are now imported from ../bench, and the output is somewhat simpler. Other than that, commands are executed the same way, such as yarn bench chunk.
I’m sorry for opening such a large PR.🙏 If there are any questions or concerns, ask for a review at any time.
I will gradually improve the output.
- ✅ I ran through all the files.
- ⚠️ But I didn’t compare them all against vitest again.
TODO
- [X] Implement bundling scripts for
es-toolkitand a benchmark file
Utilize the existing bundling setup to closely resemble the production environment.
- [X] Abstract
tinybenchto have the same interface asvitestfor convenient writing of benchmark code - [X] Implement the ability to run benchmarks via a command, specifying the file name
- [X] Modify existing benchmark files:
- [X] Remove reassigned parts
- [X] Remove Vitest dependency
The latest updates on your projects. Learn more about Vercel for Git ↗︎
| Name | Status | Preview | Comments | Updated (UTC) |
|---|---|---|---|---|
| es-toolkit | ✅ Ready (Inspect) | Visit Preview | 💬 Add feedback | Oct 19, 2024 2:22pm |
Codecov Report
All modified and coverable lines are covered by tests :white_check_mark:
Project coverage is 99.03%. Comparing base (
4b2de1f) to head (6c985f9).
Additional details and impacted files
@@ Coverage Diff @@
## main #710 +/- ##
=======================================
Coverage 99.03% 99.03%
=======================================
Files 285 285
Lines 2483 2483
Branches 706 706
=======================================
Hits 2459 2459
Misses 23 23
Partials 1 1