Skip to content

Commit b7fc957

Browse files
committed
benchmark: add url benchmarks
Based on the ad-hoc benchmark from nodejs/node-v0.x-archive#8638.
1 parent 36aeae8 commit b7fc957

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

benchmark/url/url.js

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
var common = require('../common.js');
2+
var url = require('url');
3+
4+
var bench = common.createBenchmark(main, {
5+
type: 'one two three four five'.split(' '),
6+
n: [25e4]
7+
});
8+
9+
function main(conf) {
10+
var type = conf.type;
11+
var n = conf.n | 0;
12+
13+
var inputs = {
14+
one: 'http://nodejs.org/docs/latest/api/url.html#url_url_format_urlobj',
15+
two: 'http://blog.nodejs.org/',
16+
three: 'https://encrypted.google.com/search?q=url&q=site:npmjs.org&hl=en',
17+
four: 'javascript:alert("node is awesome");',
18+
five: 'some.ran/dom/url.thing?oh=yes#whoo',
19+
};
20+
var input = inputs[type] || '';
21+
22+
bench.start();
23+
for (var i = 0; i < n; i += 1)
24+
url.parse(input);
25+
bench.end(n);
26+
}

0 commit comments

Comments
 (0)