Skip to content

Commit a1555cb

Browse files
BridgeARMylesBorins
authored andcommitted
benchmark: add more util inspect and format benchmarks
This adds a couple of benchmarks to check different options and code paths. Backport-PR-URL: #31431 PR-URL: #30767 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Denys Otrishko <[email protected]> Reviewed-By: Rich Trott <[email protected]>
1 parent a1ce776 commit a1555cb

File tree

3 files changed

+18
-6
lines changed

3 files changed

+18
-6
lines changed

benchmark/util/format.js

+2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ const inputs = {
1313
'no-replace-2': ['foobar', 'yeah', 'mensch', 5],
1414
'only-objects': [{ msg: 'This is an error' }, { msg: 'This is an error' }],
1515
'many-%': ['replace%%%%s%%%%many%s%s%s', 'percent'],
16+
'object-to-string': ['foo %s bar', { toString() { return 'bla'; } }],
17+
'object-%s': ['foo %s bar', { a: true, b: false }],
1618
};
1719

1820
const bench = common.createBenchmark(main, {

benchmark/util/inspect-proxy.js

+13-5
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,21 @@
33
const util = require('util');
44
const common = require('../common.js');
55

6-
const bench = common.createBenchmark(main, { n: [2e4] });
6+
const bench = common.createBenchmark(main, {
7+
n: [2e4],
8+
showProxy: [0, 1],
9+
isProxy: [0, 1]
10+
});
711

8-
function main({ n }) {
9-
const proxyA = new Proxy({}, { get: () => {} });
10-
const proxyB = new Proxy(() => {}, {});
12+
function main({ n, showProxy, isProxy }) {
13+
let proxyA = {};
14+
let proxyB = () => {};
15+
if (isProxy) {
16+
proxyA = new Proxy(proxyA, { get: () => {} });
17+
proxyB = new Proxy(proxyB, {});
18+
}
1119
bench.start();
1220
for (let i = 0; i < n; i += 1)
13-
util.inspect({ a: proxyA, b: proxyB }, { showProxy: true });
21+
util.inspect({ a: proxyA, b: proxyB }, { showProxy });
1422
bench.end(n);
1523
}

test/benchmark/test-benchmark-util.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,7 @@ runBenchmark('util',
1414
'size=1',
1515
'type=',
1616
'len=1',
17-
'version=native'],
17+
'version=native',
18+
'isProxy=1',
19+
'showProxy=1'],
1820
{ NODEJS_BENCHMARK_ZERO_ALLOWED: 1 });

0 commit comments

Comments
 (0)