Skip to content

Commit b95e5d7

Browse files
TrottMyles Borins
authored and
Myles Borins
committed
benchmark: add benchmark for url.format()
PR-URL: #7250 Reviewed-By: Brian White <[email protected]>
1 parent 7182f5f commit b95e5d7

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

benchmark/url/url-format.js

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
'use strict';
2+
const common = require('../common.js');
3+
const url = require('url');
4+
const v8 = require('v8');
5+
6+
const bench = common.createBenchmark(main, {
7+
type: 'one two'.split(' '),
8+
n: [25e6]
9+
});
10+
11+
function main(conf) {
12+
const type = conf.type;
13+
const n = conf.n | 0;
14+
15+
const inputs = {
16+
one: {slashes: true, host: 'localhost'},
17+
two: {protocol: 'file:', pathname: '/foo'},
18+
};
19+
const input = inputs[type] || '';
20+
21+
// Force-optimize url.format() so that the benchmark doesn't get
22+
// disrupted by the optimizer kicking in halfway through.
23+
for (const name in inputs)
24+
url.format(inputs[name]);
25+
26+
v8.setFlagsFromString('--allow_natives_syntax');
27+
eval('%OptimizeFunctionOnNextCall(url.format)');
28+
29+
bench.start();
30+
for (var i = 0; i < n; i += 1)
31+
url.format(input);
32+
bench.end(n);
33+
}

0 commit comments

Comments
 (0)