From 99099d64cb46a67d83d10737b99e0c9519c13062 Mon Sep 17 00:00:00 2001 From: Rafael Gonzaga Date: Sun, 12 Jan 2025 17:16:40 -0300 Subject: [PATCH] benchmark: add validateStream to styleText bench PR-URL: https://github.com/nodejs/node/pull/56556 Reviewed-By: Matteo Collina Reviewed-By: James M Snell Reviewed-By: Luigi Pinca --- benchmark/util/style-text.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/benchmark/util/style-text.js b/benchmark/util/style-text.js index 195907bba5c..282a96150f0 100644 --- a/benchmark/util/style-text.js +++ b/benchmark/util/style-text.js @@ -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': @@ -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 }