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
Changes from 1 commit
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
Prev Previous commit
Next Next commit
benchmark: refactor whatwg-url-properties
  • Loading branch information
joyeecheung committed Feb 15, 2017
commit 93ee65178357137768618bbea2ed67a03d072d75
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