chalk/benchmark.js

49 lines
1.1 KiB
JavaScript
Raw Normal View History

/* globals set bench */
'use strict';
2017-06-20 19:18:21 +02:00
const chalk = require('.');
2017-06-20 19:18:21 +02:00
suite('chalk', () => {
set('iterations', 100000);
2017-06-20 19:18:21 +02:00
bench('single style', () => {
chalk.red('the fox jumps over the lazy dog');
});
2017-06-20 19:18:21 +02:00
bench('several styles', () => {
2014-07-04 22:29:02 +02:00
chalk.blue.bgRed.bold('the fox jumps over the lazy dog');
});
2017-06-20 19:18:21 +02:00
const cached = chalk.blue.bgRed.bold;
bench('cached styles', () => {
cached('the fox jumps over the lazy dog');
});
2017-06-20 19:18:21 +02:00
bench('nested styles', () => {
2014-07-04 22:29:02 +02:00
chalk.red('the fox jumps', chalk.underline.bgBlue('over the lazy dog') + '!');
});
const wrappedChalk = new chalk.constructor({
wrapper: {
before: '@',
after: '#'
}
});
bench('wrapped single style', () => {
wrappedChalk.red('the fox jumps');
});
bench('wrapped several styles', () => {
wrappedChalk.blue.bgRed.bold('the fox jumps over the lazy dog');
});
const cachedWrapper = wrappedChalk.blue.bgRed.bold;
bench('cached wrapped styles', () => {
cachedWrapper('the fox jumps over the lazy dog');
});
bench('nested wrapped styles', () => {
wrappedChalk.red('the fox jumps', wrappedChalk.underline.bgBlue('over the lazy dog') + '!');
});
});