benchmark: refactor whatwg-url-properties
PR-URL: https://github.com/nodejs/node/pull/11264 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Brian White <mscdex@mscdex.net>
This commit is contained in:
parent
e571fd4f6c
commit
d8ac08a62a
@ -1,16 +1,11 @@
|
|||||||
'use strict';
|
'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');
|
const bench = common.createBenchmark(main, {
|
||||||
var URL = require('url').URL;
|
input: Object.keys(inputs),
|
||||||
|
prop: ['href', 'origin', 'protocol',
|
||||||
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:pass@foo.bar.com:21/aaa/zzz?l=24#test'
|
|
||||||
],
|
|
||||||
prop: ['toString', 'href', 'origin', 'protocol',
|
|
||||||
'username', 'password', 'host', 'hostname', 'port',
|
'username', 'password', 'host', 'hostname', 'port',
|
||||||
'pathname', 'search', 'searchParams', 'hash'],
|
'pathname', 'search', 'searchParams', 'hash'],
|
||||||
n: [1e4]
|
n: [1e4]
|
||||||
@ -34,14 +29,6 @@ function get(n, url, prop) {
|
|||||||
bench.end(n);
|
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 = {
|
const alternatives = {
|
||||||
href: 'http://user:pass@foo.bar.com:21/aaa/zzz?l=25#test',
|
href: 'http://user:pass@foo.bar.com:21/aaa/zzz?l=25#test',
|
||||||
protocol: 'https:',
|
protocol: 'https:',
|
||||||
@ -61,7 +48,8 @@ function getAlternative(prop) {
|
|||||||
|
|
||||||
function main(conf) {
|
function main(conf) {
|
||||||
const n = conf.n | 0;
|
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;
|
const prop = conf.prop;
|
||||||
|
|
||||||
switch (prop) {
|
switch (prop) {
|
||||||
@ -74,17 +62,13 @@ function main(conf) {
|
|||||||
case 'pathname':
|
case 'pathname':
|
||||||
case 'search':
|
case 'search':
|
||||||
case 'hash':
|
case 'hash':
|
||||||
|
case 'href':
|
||||||
setAndGet(n, url, prop, getAlternative(prop));
|
setAndGet(n, url, prop, getAlternative(prop));
|
||||||
break;
|
break;
|
||||||
// TODO: move href to the first group when the setter lands.
|
|
||||||
case 'href':
|
|
||||||
case 'origin':
|
case 'origin':
|
||||||
case 'searchParams':
|
case 'searchParams':
|
||||||
get(n, url, prop);
|
get(n, url, prop);
|
||||||
break;
|
break;
|
||||||
case 'toString':
|
|
||||||
stringify(n, url);
|
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
throw new Error('Unknown prop');
|
throw new Error('Unknown prop');
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user