Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit d84be84

Browse filesBrowse files
RafaelGSSmarco-ippolito
authored andcommitted
benchmark: add validateStream to styleText bench
PR-URL: #56556 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
1 parent 03878b0 commit d84be84
Copy full SHA for d84be84

File tree

Expand file treeCollapse file tree

1 file changed

+6
-2
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+6
-2
lines changed

‎benchmark/util/style-text.js

Copy file name to clipboardExpand all lines: benchmark/util/style-text.js
+6-2Lines changed: 6 additions & 2 deletions
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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.