Skip to content

Commit 4aa1afd

Browse files
RafaelGSSaduh95
authored andcommitted
benchmark: add validateStream to styleText bench
PR-URL: #56556 Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Luigi Pinca <[email protected]>
1 parent c2d5a0c commit 4aa1afd

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

benchmark/util/style-text.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,16 @@
33
const common = require('../common.js');
44

55
const { styleText } = require('node:util');
6+
const assert = require('node:assert');
67

78
const bench = common.createBenchmark(main, {
89
messageType: ['string', 'number', 'boolean', 'invalid'],
910
format: ['red', 'italic', 'invalid'],
11+
validateStream: [1, 0],
1012
n: [1e3],
1113
});
1214

13-
function main({ messageType, format, n }) {
15+
function main({ messageType, format, validateStream, n }) {
1416
let str;
1517
switch (messageType) {
1618
case 'string':
@@ -29,8 +31,10 @@ function main({ messageType, format, n }) {
2931

3032
bench.start();
3133
for (let i = 0; i < n; i++) {
34+
let colored = '';
3235
try {
33-
styleText(format, str);
36+
colored = styleText(format, str, { validateStream });
37+
assert.ok(colored); // Attempt to avoid dead-code elimination
3438
} catch {
3539
// eslint-disable no-empty
3640
}

0 commit comments

Comments
 (0)