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 eac1871

Browse filesBrowse files
joyeecheungItalo A. Casas
authored andcommitted
benchmark: improve WHATWG URL benchmarks
* add benchmark to compare the performance of getting url properties between the WHATWG URL and the legacy implementation * add benchmark to compare the performance of serializing urls between the WHATWG URL and the legacy implementation * refactor the benchmark for comparing parsing performance between the two implementations PR-URL: #10678 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Brian White <mscdex@mscdex.net>
1 parent ecf72d8 commit eac1871
Copy full SHA for eac1871

File tree

Expand file treeCollapse file tree

4 files changed

+249
-57
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

4 files changed

+249
-57
lines changed
Open diff view settings
Collapse file
+109Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
'use strict';
2+
const common = require('../common.js');
3+
const url = require('url');
4+
const URL = url.URL;
5+
const assert = require('assert');
6+
7+
const inputs = {
8+
long: 'http://nodejs.org:89/docs/latest/api/url.html#test?' +
9+
'payload1=true&payload2=false&test=1&benchmark=3&' +
10+
'foo=38.38.011.293&bar=1234834910480&test=19299&3992&' +
11+
'key=f5c65e1e98fe07e648249ad41e1cfdb0',
12+
short: 'https://nodejs.org/en/blog/',
13+
idn: 'http://你好你好',
14+
auth: 'https://user:pass@example.com/path?search=1',
15+
special: 'file:///foo/bar/test/node.js',
16+
percent: 'https://%E4%BD%A0/foo',
17+
dot: 'https://example.org/./a/../b/./c'
18+
};
19+
20+
const bench = common.createBenchmark(main, {
21+
type: Object.keys(inputs),
22+
method: ['legacy', 'whatwg'],
23+
n: [1e5]
24+
});
25+
26+
// At the time of writing, when using a passed property name to index
27+
// the object, Crankshaft would generate a LoadKeyedGeneric even when it
28+
// remains a constant in the function, so here we must use the literal
29+
// instead to get a LoadNamedField.
30+
function useLegacy(n, input) {
31+
var obj = url.parse(input);
32+
var noDead = {
33+
protocol: obj.protocol,
34+
auth: obj.auth,
35+
host: obj.host,
36+
hostname: obj.hostname,
37+
port: obj.port,
38+
pathname: obj.pathname,
39+
search: obj.search,
40+
hash: obj.hash
41+
};
42+
// It's necessary to assign the values to an object
43+
// to avoid loop invariant code motion.
44+
bench.start();
45+
for (var i = 0; i < n; i += 1) {
46+
noDead.protocol = obj.protocol;
47+
noDead.auth = obj.auth;
48+
noDead.host = obj.host;
49+
noDead.hostname = obj.hostname;
50+
noDead.port = obj.port;
51+
noDead.pathname = obj.pathname;
52+
noDead.search = obj.search;
53+
noDead.hash = obj.hash;
54+
}
55+
bench.end(n);
56+
return noDead;
57+
}
58+
59+
function useWHATWG(n, input) {
60+
var obj = new URL(input);
61+
var noDead = {
62+
protocol: obj.protocol,
63+
auth: obj.username + ':' + obj.password,
64+
host: obj.host,
65+
hostname: obj.hostname,
66+
port: obj.port,
67+
pathname: obj.pathname,
68+
search: obj.search,
69+
hash: obj.hash
70+
};
71+
bench.start();
72+
for (var i = 0; i < n; i += 1) {
73+
noDead.protocol = obj.protocol;
74+
noDead.auth = obj.username + ':' + obj.password;
75+
noDead.host = obj.host;
76+
noDead.hostname = obj.hostname;
77+
noDead.port = obj.port;
78+
noDead.pathname = obj.pathname;
79+
noDead.search = obj.search;
80+
noDead.hash = obj.hash;
81+
}
82+
bench.end(n);
83+
return noDead;
84+
}
85+
86+
function main(conf) {
87+
const type = conf.type;
88+
const n = conf.n | 0;
89+
const method = conf.method;
90+
91+
const input = inputs[type];
92+
if (!input) {
93+
throw new Error('Unknown input type');
94+
}
95+
96+
var noDead; // Avoid dead code elimination.
97+
switch (method) {
98+
case 'legacy':
99+
noDead = useLegacy(n, input);
100+
break;
101+
case 'whatwg':
102+
noDead = useWHATWG(n, input);
103+
break;
104+
default:
105+
throw new Error('Unknown method');
106+
}
107+
108+
assert.ok(noDead);
109+
}
Collapse file
+69Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
'use strict';
2+
const common = require('../common.js');
3+
const url = require('url');
4+
const URL = url.URL;
5+
const assert = require('assert');
6+
7+
const inputs = {
8+
long: 'http://nodejs.org:89/docs/latest/api/url.html#test?' +
9+
'payload1=true&payload2=false&test=1&benchmark=3&' +
10+
'foo=38.38.011.293&bar=1234834910480&test=19299&3992&' +
11+
'key=f5c65e1e98fe07e648249ad41e1cfdb0',
12+
short: 'https://nodejs.org/en/blog/',
13+
idn: 'http://你好你好',
14+
auth: 'https://user:pass@example.com/path?search=1',
15+
special: 'file:///foo/bar/test/node.js',
16+
percent: 'https://%E4%BD%A0/foo',
17+
dot: 'https://example.org/./a/../b/./c'
18+
};
19+
20+
const bench = common.createBenchmark(main, {
21+
type: Object.keys(inputs),
22+
method: ['legacy', 'whatwg'],
23+
n: [1e5]
24+
});
25+
26+
function useLegacy(n, input) {
27+
var noDead = url.parse(input);
28+
bench.start();
29+
for (var i = 0; i < n; i += 1) {
30+
noDead = url.parse(input);
31+
}
32+
bench.end(n);
33+
return noDead;
34+
}
35+
36+
function useWHATWG(n, input) {
37+
var noDead = url.parse(input);
38+
bench.start();
39+
for (var i = 0; i < n; i += 1) {
40+
noDead = new URL(input);
41+
}
42+
bench.end(n);
43+
return noDead;
44+
}
45+
46+
function main(conf) {
47+
const type = conf.type;
48+
const n = conf.n | 0;
49+
const method = conf.method;
50+
51+
const input = inputs[type];
52+
if (!input) {
53+
throw new Error('Unknown input type');
54+
}
55+
56+
var noDead; // Avoid dead code elimination.
57+
switch (method) {
58+
case 'legacy':
59+
noDead = useLegacy(n, input);
60+
break;
61+
case 'whatwg':
62+
noDead = useWHATWG(n, input);
63+
break;
64+
default:
65+
throw new Error('Unknown method');
66+
}
67+
68+
assert.ok(noDead);
69+
}
Collapse file
+71Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
'use strict';
2+
const common = require('../common.js');
3+
const url = require('url');
4+
const URL = url.URL;
5+
const assert = require('assert');
6+
7+
const inputs = {
8+
long: 'http://nodejs.org:89/docs/latest/api/url.html#test?' +
9+
'payload1=true&payload2=false&test=1&benchmark=3&' +
10+
'foo=38.38.011.293&bar=1234834910480&test=19299&3992&' +
11+
'key=f5c65e1e98fe07e648249ad41e1cfdb0',
12+
short: 'https://nodejs.org/en/blog/',
13+
idn: 'http://你好你好',
14+
auth: 'https://user:pass@example.com/path?search=1',
15+
special: 'file:///foo/bar/test/node.js',
16+
percent: 'https://%E4%BD%A0/foo',
17+
dot: 'https://example.org/./a/../b/./c'
18+
};
19+
20+
const bench = common.createBenchmark(main, {
21+
type: Object.keys(inputs),
22+
method: ['legacy', 'whatwg'],
23+
n: [1e5]
24+
});
25+
26+
function useLegacy(n, input, prop) {
27+
var obj = url.parse(input);
28+
var noDead = url.format(obj);
29+
bench.start();
30+
for (var i = 0; i < n; i += 1) {
31+
noDead = url.format(obj);
32+
}
33+
bench.end(n);
34+
return noDead;
35+
}
36+
37+
function useWHATWG(n, input, prop) {
38+
var obj = new URL(input);
39+
var noDead = obj.toString();
40+
bench.start();
41+
for (var i = 0; i < n; i += 1) {
42+
noDead = obj.toString();
43+
}
44+
bench.end(n);
45+
return noDead;
46+
}
47+
48+
function main(conf) {
49+
const type = conf.type;
50+
const n = conf.n | 0;
51+
const method = conf.method;
52+
53+
const input = inputs[type];
54+
if (!input) {
55+
throw new Error('Unknown input type');
56+
}
57+
58+
var noDead; // Avoid dead code elimination.
59+
switch (method) {
60+
case 'legacy':
61+
noDead = useLegacy(n, input);
62+
break;
63+
case 'whatwg':
64+
noDead = useWHATWG(n, input);
65+
break;
66+
default:
67+
throw new Error('Unknown method');
68+
}
69+
70+
assert.ok(noDead);
71+
}
Collapse file

‎benchmark/url/new-url-parse.js‎

Copy file name to clipboardExpand all lines: benchmark/url/new-url-parse.js
-57Lines changed: 0 additions & 57 deletions
This file was deleted.

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.