Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 08cd81b

Browse filesBrowse files
evanlucasMyles Borins
authored andcommitted
benchmark: add util.format benchmark
PR-URL: #5360 Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 7d6acef commit 08cd81b
Copy full SHA for 08cd81b

File tree

Expand file treeCollapse file tree

1 file changed

+40
-0
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+40
-0
lines changed
Open diff view settings
Collapse file

‎benchmark/util/format.js‎

Copy file name to clipboard
+40Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
'use strict';
2+
3+
const util = require('util');
4+
const common = require('../common');
5+
const v8 = require('v8');
6+
const bench = common.createBenchmark(main, {
7+
n: [1e6]
8+
, type: ['string',
9+
'number',
10+
'object',
11+
'unknown',
12+
'no-replace']
13+
});
14+
15+
const inputs = {
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+
function main(conf) {
24+
const n = conf.n | 0;
25+
const type = conf.type;
26+
27+
const input = 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 (var i = 0; i < n; i++) {
37+
util.format(input[0], input[1]);
38+
}
39+
bench.end(n);
40+
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.