Skip to content

Commit 87cdb83

Browse files
AndreasMadsenMyles Borins
authored and
Myles Borins
committed
benchmark: merge url.js with url-resolve.js
url.js was broken since it didn't use the common.js runner. This fixes that issue by merging it with url-resolve.js, which also benchmarks url.resolve. PR-URL: #5177 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Rod Vagg <[email protected]>
1 parent 921e856 commit 87cdb83

File tree

1 file changed

+25
-12
lines changed

1 file changed

+25
-12
lines changed

benchmark/url/url-resolve.js

+25-12
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,43 @@ var common = require('../common.js');
33
var url = require('url');
44
var v8 = require('v8');
55

6+
var hrefs = [
7+
'http://example.com/',
8+
'http://nodejs.org/docs/latest/api/url.html#url_url_format_urlobj',
9+
'http://blog.nodejs.org/',
10+
'https://encrypted.google.com/search?q=url&q=site:npmjs.org&hl=en',
11+
'javascript:alert("node is awesome");',
12+
'some.ran/dom/url.thing?oh=yes#whoo'
13+
];
14+
15+
16+
var paths = [
17+
'../../../../../etc/passwd',
18+
'../foo/bar?baz=boom',
19+
'foo/bar',
20+
'http://nodejs.org',
21+
'./foo/bar?baz'
22+
];
23+
624
var bench = common.createBenchmark(main, {
7-
type: ['one'],
8-
n: [1e5],
25+
href: Object.keys(hrefs),
26+
path: Object.keys(paths),
27+
n: [1e5]
928
});
1029

1130
function main(conf) {
12-
var type = conf.type;
1331
var n = conf.n | 0;
14-
15-
var inputs = {
16-
one: ['http://example.com/', '../../../../../etc/passwd'],
17-
};
18-
var input = inputs[type] || [];
32+
var href = hrefs[conf.href];
33+
var path = paths[conf.path];
1934

2035
// Force-optimize url.resolve() so that the benchmark doesn't get
2136
// disrupted by the optimizer kicking in halfway through.
22-
for (var name in inputs)
23-
url.resolve(inputs[name][0], inputs[name][1]);
24-
37+
url.resolve(href, path);
2538
v8.setFlagsFromString('--allow_natives_syntax');
2639
eval('%OptimizeFunctionOnNextCall(url.resolve)');
2740

2841
bench.start();
2942
for (var i = 0; i < n; i += 1)
30-
url.resolve(input[0], input[1]);
43+
url.resolve(href, path);
3144
bench.end(n);
3245
}

0 commit comments

Comments
 (0)