forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstyle-text.js
More file actions
43 lines (38 loc) · 926 Bytes
/
style-text.js
File metadata and controls
43 lines (38 loc) · 926 Bytes
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
'use strict';
const common = require('../common.js');
const { styleText } = require('node:util');
const assert = require('node:assert');
const bench = common.createBenchmark(main, {
messageType: ['string', 'number', 'boolean', 'invalid'],
format: ['red', 'italic', 'invalid'],
validateStream: [1, 0],
n: [1e3],
});
function main({ messageType, format, validateStream, n }) {
let str;
switch (messageType) {
case 'string':
str = 'hello world';
break;
case 'number':
str = 10;
break;
case 'boolean':
str = true;
break;
case 'invalid':
str = undefined;
break;
}
bench.start();
for (let i = 0; i < n; i++) {
let colored = '';
try {
colored = styleText(format, str, { validateStream });
assert.ok(colored); // Attempt to avoid dead-code elimination
} catch {
// eslint-disable no-empty
}
}
bench.end(n);
}