Skip to content

Commit

Permalink
misc
Browse files Browse the repository at this point in the history
  • Loading branch information
alexeyraspopov committed May 14, 2024
1 parent 5f0c047 commit 9dd71a0
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 1 deletion.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Changelog

## [v1.0.1](https://github.com/alexeyraspopov/picocolors/releases/tag/v1.0.0)
## [v1.0.1](https://github.com/alexeyraspopov/picocolors/releases/tag/v1.0.1)

- Updated color detection mechanism to work properly on Vercel Edge Runtime ([#64](https://github.com/alexeyraspopov/picocolors/pull/64))
- Remove use of recursion to avoid possible stack overflow for very long inputs ([#56](https://github.com/alexeyraspopov/picocolors/pull/56))
Expand Down
68 changes: 68 additions & 0 deletions benchmarks/recursion.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#!/usr/bin/env node

// Benchmark results are unstable. To have more stable results:
// 1. Restart OS. Do not run any applications. Put power cable to laptop.
// 2. Run tests 5 times.
// 3. Took the best result for each candidate.

let benchmark = require("benchmark")
let colorette = require("colorette")
let kleur = require("kleur")
let kleurColors = require("kleur/colors")
let chalk = require("chalk")
let ansi = require("ansi-colors")
let cliColor = require("cli-color")
let picocolors = require("../picocolors.js")
let picocolorsw = require("../picocolors-w.js")
let nanocolors = require("nanocolors")

function formatNumber(number) {
return String(number)
.replace(/\d{3}$/, ",$&")
.replace(/^(\d|\d\d)(\d{3},)/, "$1,$2")
}

let suite = new benchmark.Suite()
let out
let count = 1000
let input = "lorem ipsum dolor sit amet"

suite
.add("chalk", () => {
out = chalk.blue(chalk.red(input).repeat(count))
})
.add("cli-color", () => {
out = cliColor.blue(cliColor.red(input).repeat(count))
})
.add("ansi-colors", () => {
out = ansi.blue(ansi.red(input).repeat(count))
})
.add("kleur", () => {
out = kleur.blue(kleur.red(input).repeat(count))
})
.add("kleur/colors", () => {
out = kleurColors.blue(kleurColors.red(input).repeat(count))
})
.add("colorette", () => {
out = colorette.blue(colorette.red(input).repeat(count))
})
.add("nanocolors", () => {
out = nanocolors.blue(nanocolors.red(input).repeat(count))
})
.add("picocolors", () => {
out = picocolors.blue(picocolors.red(input).repeat(count))
})
.add("updated", () => {
out = picocolorsw.blue(picocolorsw.red(input).repeat(count))
})
.on("cycle", event => {
let prefix = event.target.name === "picocolors" ? "+ " : " "
let name = event.target.name.padEnd("kleur/colors ".length)
let hz = formatNumber(event.target.hz.toFixed(0)).padStart(10)
process.stdout.write(`${prefix}${name}${picocolors.bold(hz)} ops/sec\n`)
})
.on("error", event => {
process.stderr.write(picocolors.red(event.target.error.toString()) + "\n")
process.exit(1)
})
.run()

0 comments on commit 9dd71a0

Please # to comment.