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 87cdb83

Browse filesBrowse files
AndreasMadsenMyles Borins
authored andcommitted
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 <jasnell@gmail.com> Reviewed-By: Rod Vagg <rod@vagg.org>
1 parent 921e856 commit 87cdb83
Copy full SHA for 87cdb83

File tree

Expand file treeCollapse file tree

1 file changed

+25
-12
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+25
-12
lines changed
Open diff view settings
Collapse file

‎benchmark/url/url-resolve.js‎

Copy file name to clipboardExpand all lines: benchmark/url/url-resolve.js
+25-12Lines changed: 25 additions & 12 deletions
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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.