| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,39 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + | ||
| 3 | + const common = require('../common.js'); | ||
| 4 | + | ||
| 5 | + const { styleText } = require('node:util'); | ||
| 6 | + | ||
| 7 | + const bench = common.createBenchmark(main, { | ||
| 8 | + messageType: ['string', 'number', 'boolean', 'invalid'], | ||
| 9 | + format: ['red', 'italic', 'invalid'], | ||
| 10 | + n: [1e3], | ||
| 11 | + }); | ||
| 12 | + | ||
| 13 | + function main({ messageType, format, n }) { | ||
| 14 | + let str; | ||
| 15 | + switch (messageType) { | ||
| 16 | + case 'string': | ||
| 17 | + str = 'hello world'; | ||
| 18 | + break; | ||
| 19 | + case 'number': | ||
| 20 | + str = 10; | ||
| 21 | + break; | ||
| 22 | + case 'boolean': | ||
| 23 | + str = true; | ||
| 24 | + break; | ||
| 25 | + case 'invalid': | ||
| 26 | + str = undefined; | ||
| 27 | + break; | ||
| 28 | + } | ||
| 29 | + | ||
| 30 | + bench.start(); | ||
| 31 | + for (let i = 0; i < n; i++) { | ||
| 32 | + try { | ||
| 33 | + styleText(format, str); | ||
| 34 | + } catch { | ||
| 35 | + // eslint-disable no-empty | ||
| 36 | + } | ||
| 37 | + } | ||
| 38 | + bench.end(n); | ||
| 39 | + } | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments