Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions benchmark/url/url.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
var common = require('../common.js');
var url = require('url');

var bench = common.createBenchmark(main, {
type: 'one two three four five'.split(' '),
n: [25e4]
});

function main(conf) {
var type = conf.type;
var n = conf.n | 0;

var inputs = {
one: 'http://nodejs.org/docs/latest/api/url.html#url_url_format_urlobj',
two: 'http://blog.nodejs.org/',
three: 'https://encrypted.google.com/search?q=url&q=site:npmjs.org&hl=en',
four: 'javascript:alert("node is awesome");',
five: 'some.ran/dom/url.thing?oh=yes#whoo',
};
var input = inputs[type] || '';

bench.start();
for (var i = 0; i < n; i += 1)
url.parse(input);
bench.end(n);
}
10 changes: 6 additions & 4 deletions lib/url.js
Original file line number Diff line number Diff line change
Expand Up @@ -319,11 +319,13 @@ Url.prototype.parse = function(url, parseQueryString, slashesDenoteHost) {
// need to be.
for (var i = 0, l = autoEscape.length; i < l; i++) {
var ae = autoEscape[i];
var esc = encodeURIComponent(ae);
if (esc === ae) {
esc = escape(ae);
if (rest.indexOf(ae) !== -1) {
var esc = encodeURIComponent(ae);
if (esc === ae) {
esc = escape(ae);
}
rest = rest.split(ae).join(esc);
}
rest = rest.split(ae).join(esc);
}
}

Expand Down