From 23812f56e5a78cd99d7a408d138fba9fae69ebfe Mon Sep 17 00:00:00 2001 From: RafaelGSS Date: Fri, 10 Jan 2025 17:04:55 -0300 Subject: [PATCH 1/2] benchmark: add validateStream to styleText bench --- benchmark/util/style-text.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/benchmark/util/style-text.js b/benchmark/util/style-text.js index 195907bba5c628..5fe94409599ac8 100644 --- a/benchmark/util/style-text.js +++ b/benchmark/util/style-text.js @@ -7,10 +7,11 @@ const { styleText } = require('node:util'); 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 +30,10 @@ function main({ messageType, format, n }) { bench.start(); for (let i = 0; i < n; i++) { + let colored = '' try { - styleText(format, str); + colored = util.styleText(format, str, { validateStream }); + assert.ok(colored); // Attempt to avoid dead-code elimination } catch { // eslint-disable no-empty } From 6580f3fd5dc4b4d9f2d0b94cba3eb0442f7dea81 Mon Sep 17 00:00:00 2001 From: RafaelGSS Date: Fri, 10 Jan 2025 17:08:16 -0300 Subject: [PATCH 2/2] fixup! benchmark: add validateStream to styleText bench --- benchmark/util/style-text.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/benchmark/util/style-text.js b/benchmark/util/style-text.js index 5fe94409599ac8..282a96150f0b94 100644 --- a/benchmark/util/style-text.js +++ b/benchmark/util/style-text.js @@ -3,6 +3,7 @@ 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'], @@ -30,9 +31,9 @@ function main({ messageType, format, validateStream, n }) { bench.start(); for (let i = 0; i < n; i++) { - let colored = '' + let colored = ''; try { - colored = util.styleText(format, str, { validateStream }); + colored = styleText(format, str, { validateStream }); assert.ok(colored); // Attempt to avoid dead-code elimination } catch { // eslint-disable no-empty