forked from ai/nanocolors
/
simple-benchmark.js
executable file
·57 lines (52 loc) · 1.54 KB
/
simple-benchmark.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/usr/bin/env node
import benchmark from 'benchmark'
import * as colorette from 'colorette'
import kleur from 'kleur'
import * as kleurColors from 'kleur/colors'
import chalk from 'chalk'
import ansi from 'ansi-colors'
import cliColor from 'cli-color'
import * as pen from 'felt-pen'
import * as nanocolors from 'nanocolors'
import * as forkcolours from '../index.js'
function formatNumber(number) {
return String(number)
.replace(/\d{3}$/, ',$&')
.replace(/^(\d|\d\d)(\d{3},)/, '$1,$2')
}
let suite = new benchmark.Suite()
let out
suite
.add('chalk', () => {
out = chalk.red(chalk.bold('bold') + ' red')
})
.add('cli-color', () => {
out = cliColor.red(cliColor.bold('bold') + ' red')
})
.add('ansi-colors', () => {
out = ansi.red(ansi.bold('bold') + ' red')
})
.add('kleur', () => {
out = kleur.red(kleur.bold('bold') + ' red')
})
.add('kleur/colors', () => {
out = kleurColors.red(kleurColors.bold('bold') + ' red')
})
.add('felt-pen', () => {
out = pen.red(pen.bold('bold') + ' red')
})
.add('colorette', () => {
out = colorette.red(colorette.bold('bold') + ' red')
})
.add('nanocolors', () => {
out = nanocolors.red(nanocolors.bold('bold') + ' red')
})
.add('forkcolours', () => {
out = forkcolours.red(forkcolours.bold('bold') + ' red')
})
.on('cycle', event => {
let name = event.target.name.padEnd('kleur/colors '.length)
let hz = formatNumber(event.target.hz.toFixed(0)).padStart(10)
process.stdout.write(`${name}${nanocolors.bold(hz)} ops/sec\n`)
})
.run()