mirror of
https://github.com/zebrajr/node.git
synced 2025-12-06 12:20:27 +01:00
benchmark: add style-text benchmark
PR-URL: https://github.com/nodejs/node/pull/52004 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Moshe Atlow <moshe@atlow.co.il> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
This commit is contained in:
parent
5d13419dbd
commit
bda66ad711
39
benchmark/util/style-text.js
Normal file
39
benchmark/util/style-text.js
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
'use strict';
|
||||
|
||||
const common = require('../common.js');
|
||||
|
||||
const { styleText } = require('node:util');
|
||||
|
||||
const bench = common.createBenchmark(main, {
|
||||
messageType: ['string', 'number', 'boolean', 'invalid'],
|
||||
format: ['red', 'italic', 'invalid'],
|
||||
n: [1e3],
|
||||
});
|
||||
|
||||
function main({ messageType, format, n }) {
|
||||
let str;
|
||||
switch (messageType) {
|
||||
case 'string':
|
||||
str = 'hello world';
|
||||
break;
|
||||
case 'number':
|
||||
str = 10;
|
||||
break;
|
||||
case 'boolean':
|
||||
str = true;
|
||||
break;
|
||||
case 'invalid':
|
||||
str = undefined;
|
||||
break;
|
||||
}
|
||||
|
||||
bench.start();
|
||||
for (let i = 0; i < n; i++) {
|
||||
try {
|
||||
styleText(format, str);
|
||||
} catch {
|
||||
// eslint-disable no-empty
|
||||
}
|
||||
}
|
||||
bench.end(n);
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user