forked from orbit-oss/chalk
Improve performance greatly (#337)
This commit is contained in:
parent
983094883c
commit
c08417e88c
6 changed files with 159 additions and 60 deletions
42
benchmark.js
42
benchmark.js
|
|
@ -3,22 +3,48 @@
|
|||
const chalk = require('.');
|
||||
|
||||
suite('chalk', () => {
|
||||
set('iterations', 100000);
|
||||
set('iterations', 1000000);
|
||||
|
||||
bench('single style', () => {
|
||||
const chalkRed = chalk.red;
|
||||
const chalkBgRed = chalk.bgRed;
|
||||
const chalkBlueBgRed = chalk.blue.bgRed;
|
||||
const chalkBlueBgRedBold = chalk.blue.bgRed.bold;
|
||||
|
||||
const blueStyledString = 'the fox jumps' + chalk.blue('over the lazy dog') + '!';
|
||||
|
||||
bench('1 style', () => {
|
||||
chalk.red('the fox jumps over the lazy dog');
|
||||
});
|
||||
|
||||
bench('several styles', () => {
|
||||
bench('2 styles', () => {
|
||||
chalk.blue.bgRed('the fox jumps over the lazy dog');
|
||||
});
|
||||
|
||||
bench('3 styles', () => {
|
||||
chalk.blue.bgRed.bold('the fox jumps over the lazy dog');
|
||||
});
|
||||
|
||||
const cached = chalk.blue.bgRed.bold;
|
||||
bench('cached styles', () => {
|
||||
cached('the fox jumps over the lazy dog');
|
||||
bench('cached: 1 style', () => {
|
||||
chalkRed('the fox jumps over the lazy dog');
|
||||
});
|
||||
|
||||
bench('nested styles', () => {
|
||||
chalk.red('the fox jumps', chalk.underline.bgBlue('over the lazy dog') + '!');
|
||||
bench('cached: 2 styles', () => {
|
||||
chalkBlueBgRed('the fox jumps over the lazy dog');
|
||||
});
|
||||
|
||||
bench('cached: 3 styles', () => {
|
||||
chalkBlueBgRedBold('the fox jumps over the lazy dog');
|
||||
});
|
||||
|
||||
bench('cached: 1 style with newline', () => {
|
||||
chalkRed('the fox jumps\nover the lazy dog');
|
||||
});
|
||||
|
||||
bench('cached: 1 style nested intersecting', () => {
|
||||
chalkRed(blueStyledString);
|
||||
});
|
||||
|
||||
bench('cached: 1 style nested non-intersecting', () => {
|
||||
chalkBgRed(blueStyledString);
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue