forked from chalk/chalk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbenchmark.js
57 lines (44 loc) · 1.45 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
51
52
53
54
55
56
57
/* globals suite, bench */
import chalk from './index.js';
suite('chalk', () => {
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);
});
bench('cached: 1 style template literal', () => {
// eslint-disable-next-line no-unused-expressions
chalkRed`the fox jumps over the lazy dog`;
});
bench('cached: nested styles template literal', () => {
// eslint-disable-next-line no-unused-expressions
chalkRed`the fox {bold jumps} over the {underline lazy} dog`;
});
});