-
Notifications
You must be signed in to change notification settings - Fork 29.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PR-URL: #52004 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Moshe Atlow <moshe@atlow.co.il> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
- Loading branch information
1 parent
a223ca4
commit c00715c
Showing
1 changed file
with
39 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} |