Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update benchmarks for Chalk (and other packages) #45

Open
kytta opened this issue Dec 7, 2021 · 2 comments · May be fixed by #61
Open

Update benchmarks for Chalk (and other packages) #45

kytta opened this issue Dec 7, 2021 · 2 comments · May be fixed by #61

Comments

@kytta
Copy link

kytta commented Dec 7, 2021

Chalk has got a new version, which is now also dependency-less, lightweight, and fast. cli-color and nanocolors also had updates. In other words, the benchmarks are now very inaccurate :)

A problem one might encounter is that Chalk is now ESM-only, which makes it impossible to use in the current benchmark setup. I've tried a basic bundle using ESBuild, and it works. Here's how:

  1. Clone chalk/chalk
  2. In source/index.js, replace
    • #ansi-styles with ./vendor/ansi-styles/index.js
    • #supports-color with ./vendor/supports-color/index.js
  3. Run npx esbuild source/index.js --outfile=dist/chalk.js --bundle --platform=node
  4. Copy dist/chalk.js to picocolors' repo under benchmarks/chalk.js
  5. Inside ./benchmarks, replace across all files
    • let chalk = require("chalk") with let chalk = require("./chalk").default

I could run the benchmarks on my machine, but it's slower than the one used for README, so I'm not sure if it makes sense for me to send a PR with this data...


P. S. Since many packages still use Chalk v4, I propose adding another line to the benchmarks:

$ node ./benchmarks/size.js 
Data from packagephobia.com
  chalk@4     101 kB
  chalk@5      41 kB
  cli-color   984 kB
  ansi-colors  25 kB
  kleur        21 kB
  colorette    17 kB
  nanocolors   15 kB
+ picocolors    7 kB
@alexeyraspopov
Copy link
Owner

I'd definitely separate chalk v4 and v5 in the benchmark stats. As for ESM/CJS, it may possibly be easier to make a separate environment for running ESM-first benchmarks

@prantlf
Copy link

prantlf commented Feb 25, 2024

I implemented @kytta's workaround for ESM-only packages for chalk 5 and yoctocolors in #61. picocolors was dethroned by yoctocolors in the execution speed, but not in module-loading speed yet :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants