mirror of https://github.com/nodejs/node.git
benchmark: add validateStream to styleText bench
PR-URL: https://github.com/nodejs/node/pull/56556 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>pull/56292/head
parent
4c2739348d
commit
99099d64cb
|
@ -3,14 +3,16 @@
|
||||||
const common = require('../common.js');
|
const common = require('../common.js');
|
||||||
|
|
||||||
const { styleText } = require('node:util');
|
const { styleText } = require('node:util');
|
||||||
|
const assert = require('node:assert');
|
||||||
|
|
||||||
const bench = common.createBenchmark(main, {
|
const bench = common.createBenchmark(main, {
|
||||||
messageType: ['string', 'number', 'boolean', 'invalid'],
|
messageType: ['string', 'number', 'boolean', 'invalid'],
|
||||||
format: ['red', 'italic', 'invalid'],
|
format: ['red', 'italic', 'invalid'],
|
||||||
|
validateStream: [1, 0],
|
||||||
n: [1e3],
|
n: [1e3],
|
||||||
});
|
});
|
||||||
|
|
||||||
function main({ messageType, format, n }) {
|
function main({ messageType, format, validateStream, n }) {
|
||||||
let str;
|
let str;
|
||||||
switch (messageType) {
|
switch (messageType) {
|
||||||
case 'string':
|
case 'string':
|
||||||
|
@ -29,8 +31,10 @@ function main({ messageType, format, n }) {
|
||||||
|
|
||||||
bench.start();
|
bench.start();
|
||||||
for (let i = 0; i < n; i++) {
|
for (let i = 0; i < n; i++) {
|
||||||
|
let colored = '';
|
||||||
try {
|
try {
|
||||||
styleText(format, str);
|
colored = styleText(format, str, { validateStream });
|
||||||
|
assert.ok(colored); // Attempt to avoid dead-code elimination
|
||||||
} catch {
|
} catch {
|
||||||
// eslint-disable no-empty
|
// eslint-disable no-empty
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue