forked from chalk/chalk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbenchmark.js
50 lines (38 loc) · 1.17 KB
/
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
/* globals suite, set, bench */
'use strict';
const chalk = require('.');
suite('chalk', () => {
set('iterations', 1000000);
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('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');
});
bench('cached: 1 style', () => {
chalkRed('the fox jumps 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);
});
});