Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

benchmark: unify input to url-related benchmarks #11264

Closed
wants to merge 3 commits into from
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
30 changes: 30 additions & 0 deletions benchmark/fixtures/url-inputs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
'use strict';

exports.urls = {
long: 'http://nodejs.org:89/docs/latest/api/foo/bar/qua/13949281/0f28b/' +
'/5d49/b3020/url.html#test?payload1=true&payload2=false&test=1' +
'&benchmark=3&foo=38.38.011.293&bar=1234834910480&test=19299&3992&' +
'key=f5c65e1e98fe07e648249ad41e1cfdb0',
short: 'https://nodejs.org/en/blog/',
idn: 'http://你好你好.在线',
auth: 'https://user:[email protected]/path?search=1',
file: 'file:///foo/bar/test/node.js',
ws: 'ws://localhost:9229/f46db715-70df-43ad-a359-7f9949f39868',
javascript: 'javascript:alert("node is awesome");',
percent: 'https://%E4%BD%A0/foo',
dot: 'https://example.org/./a/../b/./c'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we add mailto:[email protected] into here as an example case of mailto protocol?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That should probably just hit the same code paths as 'javascript:alert("node is awesome");'

};

exports.searchParams = {
noencode: 'foo=bar&baz=quux&xyzzy=thud',
multicharsep: 'foo=bar&&&&&&&&&&baz=quux&&&&&&&&&&xyzzy=thud',
encodefake: 'foo=%©ar&baz=%A©uux&xyzzy=%©ud',
encodemany: '%66%6F%6F=bar&%62%61%7A=quux&xyzzy=%74h%75d',
encodelast: 'foo=bar&baz=quux&xyzzy=thu%64',
multivalue: 'foo=bar&foo=baz&foo=quux&quuy=quuz',
multivaluemany: 'foo=bar&foo=baz&foo=quux&quuy=quuz&foo=abc&foo=def&' +
'foo=ghi&foo=jkl&foo=mno&foo=pqr&foo=stu&foo=vwxyz',
manypairs: 'a&b&c&d&e&f&g&h&i&j&k&l&m&n&o&p&q&r&s&t&u&v&w&x&y&z',
manyblankpairs: '&&&&&&&&&&&&&&&&&&&&&&&&',
altspaces: 'foo+bar=baz+quux&xyzzy+thud=quuy+quuz&abc=def+ghi'
};
15 changes: 1 addition & 14 deletions benchmark/querystring/querystring-parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,7 @@
var common = require('../common.js');
var querystring = require('querystring');
var v8 = require('v8');

var inputs = {
noencode: 'foo=bar&baz=quux&xyzzy=thud',
multicharsep: 'foo=bar&&&&&&&&&&baz=quux&&&&&&&&&&xyzzy=thud',
encodefake: 'foo=%©ar&baz=%A©uux&xyzzy=%©ud',
encodemany: '%66%6F%6F=bar&%62%61%7A=quux&xyzzy=%74h%75d',
encodelast: 'foo=bar&baz=quux&xyzzy=thu%64',
multivalue: 'foo=bar&foo=baz&foo=quux&quuy=quuz',
multivaluemany: 'foo=bar&foo=baz&foo=quux&quuy=quuz&foo=abc&foo=def&' +
'foo=ghi&foo=jkl&foo=mno&foo=pqr&foo=stu&foo=vwxyz',
manypairs: 'a&b&c&d&e&f&g&h&i&j&k&l&m&n&o&p&q&r&s&t&u&v&w&x&y&z',
manyblankpairs: '&&&&&&&&&&&&&&&&&&&&&&&&',
altspaces: 'foo+bar=baz+quux&xyzzy+thud=quuy+quuz&abc=def+ghi'
};
var inputs = require('../fixtures/url-inputs.js').searchParams;

var bench = common.createBenchmark(main, {
type: Object.keys(inputs),
Expand Down
14 changes: 1 addition & 13 deletions benchmark/url/legacy-vs-whatwg-url-get-prop.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,7 @@ const common = require('../common.js');
const url = require('url');
const URL = url.URL;
const assert = require('assert');

const inputs = {
long: 'http://nodejs.org:89/docs/latest/api/url.html#test?' +
'payload1=true&payload2=false&test=1&benchmark=3&' +
'foo=38.38.011.293&bar=1234834910480&test=19299&3992&' +
'key=f5c65e1e98fe07e648249ad41e1cfdb0',
short: 'https://nodejs.org/en/blog/',
idn: 'http://你好你好',
auth: 'https://user:[email protected]/path?search=1',
special: 'file:///foo/bar/test/node.js',
percent: 'https://%E4%BD%A0/foo',
dot: 'https://example.org/./a/../b/./c'
};
const inputs = require('../fixtures/url-inputs.js').urls;

const bench = common.createBenchmark(main, {
type: Object.keys(inputs),
Expand Down
14 changes: 1 addition & 13 deletions benchmark/url/legacy-vs-whatwg-url-parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,7 @@ const common = require('../common.js');
const url = require('url');
const URL = url.URL;
const assert = require('assert');

const inputs = {
long: 'http://nodejs.org:89/docs/latest/api/url.html#test?' +
'payload1=true&payload2=false&test=1&benchmark=3&' +
'foo=38.38.011.293&bar=1234834910480&test=19299&3992&' +
'key=f5c65e1e98fe07e648249ad41e1cfdb0',
short: 'https://nodejs.org/en/blog/',
idn: 'http://你好你好',
auth: 'https://user:[email protected]/path?search=1',
special: 'file:///foo/bar/test/node.js',
percent: 'https://%E4%BD%A0/foo',
dot: 'https://example.org/./a/../b/./c'
};
const inputs = require('../fixtures/url-inputs.js').urls;

const bench = common.createBenchmark(main, {
type: Object.keys(inputs),
Expand Down
13 changes: 1 addition & 12 deletions benchmark/url/legacy-vs-whatwg-url-searchparams-parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,7 @@
const common = require('../common.js');
const { URLSearchParams } = require('url');
const querystring = require('querystring');

const inputs = {
noencode: 'foo=bar&baz=quux&xyzzy=thud',
encodemany: '%66%6F%6F=bar&%62%61%7A=quux&xyzzy=%74h%75d',
encodefake: 'foo=%©ar&baz=%A©uux&xyzzy=%©ud',
encodelast: 'foo=bar&baz=quux&xyzzy=thu%64',
multicharsep: 'foo=bar&&&&&&&&&&baz=quux&&&&&&&&&&xyzzy=thud',
multivalue: 'foo=bar&foo=baz&foo=quux&quuy=quuz',
multivaluemany: 'foo=bar&foo=baz&foo=quux&quuy=quuz&foo=abc&foo=def&' +
'foo=ghi&foo=jkl&foo=mno&foo=pqr&foo=stu&foo=vwxyz',
manypairs: 'a&b&c&d&e&f&g&h&i&j&k&l&m&n&o&p&q&r&s&t&u&v&w&x&y&z'
};
const inputs = require('../fixtures/url-inputs.js').searchParams;

const bench = common.createBenchmark(main, {
type: Object.keys(inputs),
Expand Down
13 changes: 1 addition & 12 deletions benchmark/url/legacy-vs-whatwg-url-searchparams-serialize.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,7 @@
const common = require('../common.js');
const { URLSearchParams } = require('url');
const querystring = require('querystring');

const inputs = {
noencode: 'foo=bar&baz=quux&xyzzy=thud',
encodemany: '%66%6F%6F=bar&%62%61%7A=quux&xyzzy=%74h%75d',
encodefake: 'foo=%©ar&baz=%A©uux&xyzzy=%©ud',
encodelast: 'foo=bar&baz=quux&xyzzy=thu%64',
multicharsep: 'foo=bar&&&&&&&&&&baz=quux&&&&&&&&&&xyzzy=thud',
multivalue: 'foo=bar&foo=baz&foo=quux&quuy=quuz',
multivaluemany: 'foo=bar&foo=baz&foo=quux&quuy=quuz&foo=abc&foo=def&' +
'foo=ghi&foo=jkl&foo=mno&foo=pqr&foo=stu&foo=vwxyz',
manypairs: 'a&b&c&d&e&f&g&h&i&j&k&l&m&n&o&p&q&r&s&t&u&v&w&x&y&z'
};
const inputs = require('../fixtures/url-inputs.js').searchParams;

const bench = common.createBenchmark(main, {
type: Object.keys(inputs),
Expand Down
14 changes: 1 addition & 13 deletions benchmark/url/legacy-vs-whatwg-url-serialize.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,7 @@ const common = require('../common.js');
const url = require('url');
const URL = url.URL;
const assert = require('assert');

const inputs = {
long: 'http://nodejs.org:89/docs/latest/api/url.html#test?' +
'payload1=true&payload2=false&test=1&benchmark=3&' +
'foo=38.38.011.293&bar=1234834910480&test=19299&3992&' +
'key=f5c65e1e98fe07e648249ad41e1cfdb0',
short: 'https://nodejs.org/en/blog/',
idn: 'http://你好你好',
auth: 'https://user:[email protected]/path?search=1',
special: 'file:///foo/bar/test/node.js',
percent: 'https://%E4%BD%A0/foo',
dot: 'https://example.org/./a/../b/./c'
};
const inputs = require('../fixtures/url-inputs.js').urls;

const bench = common.createBenchmark(main, {
type: Object.keys(inputs),
Expand Down
11 changes: 6 additions & 5 deletions benchmark/url/url-format.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,20 @@ const common = require('../common.js');
const url = require('url');
const v8 = require('v8');

const inputs = {
slashes: {slashes: true, host: 'localhost'},
file: {protocol: 'file:', pathname: '/foo'},
};

const bench = common.createBenchmark(main, {
type: 'one two'.split(' '),
type: Object.keys(inputs),
n: [25e6]
});

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

const inputs = {
one: {slashes: true, host: 'localhost'},
two: {protocol: 'file:', pathname: '/foo'},
};
const input = inputs[type] || '';

// Force-optimize url.format() so that the benchmark doesn't get
Expand Down
37 changes: 0 additions & 37 deletions benchmark/url/url-parse.js

This file was deleted.

40 changes: 16 additions & 24 deletions benchmark/url/url-resolve.js
Original file line number Diff line number Diff line change
@@ -1,36 +1,28 @@
'use strict';
var common = require('../common.js');
var url = require('url');
var v8 = require('v8');
const common = require('../common.js');
const url = require('url');
const v8 = require('v8');
const hrefs = require('../fixtures/url-inputs.js').urls;
hrefs.noscheme = 'some.ran/dom/url.thing?oh=yes#whoo';

var hrefs = [
'http://example.com/',
'http://nodejs.org/docs/latest/api/url.html#url_url_format_urlobj',
'http://blog.nodejs.org/',
'https://encrypted.google.com/search?q=url&q=site:npmjs.org&hl=en',
'javascript:alert("node is awesome");',
'some.ran/dom/url.thing?oh=yes#whoo'
];
const paths = {
'up': '../../../../../etc/passwd',
'sibling': '../foo/bar?baz=boom',
'foo/bar': 'foo/bar',
'withscheme': 'http://nodejs.org',
'down': './foo/bar?baz'
};


var paths = [
'../../../../../etc/passwd',
'../foo/bar?baz=boom',
'foo/bar',
'http://nodejs.org',
'./foo/bar?baz'
];

var bench = common.createBenchmark(main, {
const bench = common.createBenchmark(main, {
href: Object.keys(hrefs),
path: Object.keys(paths),
n: [1e5]
});

function main(conf) {
var n = conf.n | 0;
var href = hrefs[conf.href];
var path = paths[conf.path];
const n = conf.n | 0;
const href = hrefs[conf.href];
const path = paths[conf.path];

// Force-optimize url.resolve() so that the benchmark doesn't get
// disrupted by the optimizer kicking in halfway through.
Expand Down
34 changes: 9 additions & 25 deletions benchmark/url/whatwg-url-properties.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
'use strict';
const common = require('../common.js');
const URL = require('url').URL;
const inputs = require('../fixtures/url-inputs.js').urls;

var common = require('../common.js');
var URL = require('url').URL;

var bench = common.createBenchmark(main, {
url: [
'http://example.com/',
'https://encrypted.google.com/search?q=url&q=site:npmjs.org&hl=en',
'javascript:alert("node is awesome");',
'http://user:[email protected]:21/aaa/zzz?l=24#test'
],
prop: ['toString', 'href', 'origin', 'protocol',
const bench = common.createBenchmark(main, {
input: Object.keys(inputs),
prop: ['href', 'origin', 'protocol',
'username', 'password', 'host', 'hostname', 'port',
'pathname', 'search', 'searchParams', 'hash'],
n: [1e4]
Expand All @@ -34,14 +29,6 @@ function get(n, url, prop) {
bench.end(n);
}

function stringify(n, url, prop) {
bench.start();
for (var i = 0; i < n; i += 1) {
url.toString();
}
bench.end(n);
}

const alternatives = {
href: 'http://user:[email protected]:21/aaa/zzz?l=25#test',
protocol: 'https:',
Expand All @@ -61,7 +48,8 @@ function getAlternative(prop) {

function main(conf) {
const n = conf.n | 0;
const url = new URL(conf.url);
const input = inputs[conf.input];
const url = new URL(input);
const prop = conf.prop;

switch (prop) {
Expand All @@ -74,17 +62,13 @@ function main(conf) {
case 'pathname':
case 'search':
case 'hash':
case 'href':
setAndGet(n, url, prop, getAlternative(prop));
break;
// TODO: move href to the first group when the setter lands.
case 'href':
case 'origin':
case 'searchParams':
get(n, url, prop);
break;
case 'toString':
stringify(n, url);
break;
default:
throw new Error('Unknown prop');
}
Expand Down