Skip to content

Commit 73e3c15

Browse files
BridgeARBethGriggs
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 0074790 commit 73e3c15

File tree

3 files changed

+18
-6
lines changed

3 files changed

+18
-6
lines changed

‎benchmark/util/format.js‎

Lines changed: 2 additions & 0 deletions
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
constbench=common.createBenchmark(main,{

‎benchmark/util/inspect-proxy.js‎

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,21 @@
33
constutil=require('util');
44
constcommon=require('../common.js');
55

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

8-
functionmain({ n }){
9-
constproxyA=newProxy({},{get: ()=>{}});
10-
constproxyB=newProxy(()=>{},{});
12+
functionmain({ n, showProxy, isProxy }){
13+
letproxyA={};
14+
letproxyB=()=>{};
15+
if(isProxy){
16+
proxyA=newProxy(proxyA,{get: ()=>{}});
17+
proxyB=newProxy(proxyB,{});
18+
}
1119
bench.start();
1220
for(leti=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‎

Lines changed: 3 additions & 1 deletion
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)