Skip to content

Commit 08cd81b

Browse files
evanlucasMyles Borins
authored andcommitted
benchmark: add util.format benchmark
PR-URL: #5360 Reviewed-By: James M Snell <[email protected]>
1 parent 7d6acef commit 08cd81b

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

‎benchmark/util/format.js‎

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
'use strict';
2+
3+
constutil=require('util');
4+
constcommon=require('../common');
5+
constv8=require('v8');
6+
constbench=common.createBenchmark(main,{
7+
n: [1e6]
8+
,type: ['string',
9+
'number',
10+
'object',
11+
'unknown',
12+
'no-replace']
13+
});
14+
15+
constinputs={
16+
'string': ['Hello, my name is %s','fred'],
17+
'number': ['Hi, I was born in %d',1942],
18+
'object': ['An error occurred %j',{msg: 'This is an error',code: 'ERR'}],
19+
'unknown': ['hello %a','test'],
20+
'no-replace': [1,2]
21+
};
22+
23+
functionmain(conf){
24+
constn=conf.n|0;
25+
consttype=conf.type;
26+
27+
constinput=inputs[type];
28+
29+
v8.setFlagsFromString('--allow_natives_syntax');
30+
31+
util.format(input[0],input[1]);
32+
eval('%OptimizeFunctionOnNextCall(util.format)');
33+
util.format(input[0],input[1]);
34+
35+
bench.start();
36+
for(vari=0;i<n;i++){
37+
util.format(input[0],input[1]);
38+
}
39+
bench.end(n);
40+
}

0 commit comments

Comments
(0)