Skip to content

Commit

Permalink
benchmark: add validateStream to styleText bench
Browse files Browse the repository at this point in the history
PR-URL: #56556
Reviewed-By: Matteo Collina <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
  • Loading branch information
RafaelGSS authored Jan 12, 2025
1 parent 4c27393 commit 99099d6
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions benchmark/util/style-text.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@
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, n }) {
function main({ messageType, format, validateStream, n }) {
let str;
switch (messageType) {
case 'string':
Expand All @@ -29,8 +31,10 @@ function main({ messageType, format, n }) {

bench.start();
for (let i = 0; i < n; i++) {
let colored = '';
try {
styleText(format, str);
colored = styleText(format, str, { validateStream });
assert.ok(colored); // Attempt to avoid dead-code elimination
} catch {
// eslint-disable no-empty
}
Expand Down

0 comments on commit 99099d6

Please sign in to comment.