Skip to content

Commit

Permalink
benchmark: (url) refactor
Browse files Browse the repository at this point in the history
PR-URL: #18320
Reviewed-By: James M Snell <[email protected]>
  • Loading branch information
BridgeAR authored and MylesBorins committed Feb 21, 2018
1 parent 0851822 commit 76cb958
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 49 deletions.
4 changes: 2 additions & 2 deletions benchmark/url/legacy-vs-whatwg-url-get-prop.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ function useWHATWG(n, input) {
function main({ type, n, method }) {
const input = inputs[type];
if (!input) {
throw new Error('Unknown input type');
throw new Error(`Unknown input type "${type}"`);
}

var noDead; // Avoid dead code elimination.
Expand All @@ -86,7 +86,7 @@ function main({ type, n, method }) {
noDead = useWHATWG(n, input);
break;
default:
throw new Error('Unknown method');
throw new Error(`Unknown method "${method}"`);
}

assert.ok(noDead);
Expand Down
4 changes: 2 additions & 2 deletions benchmark/url/legacy-vs-whatwg-url-parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ function useWHATWG(n, input) {
function main({ type, n, method }) {
const input = inputs[type];
if (!input) {
throw new Error('Unknown input type');
throw new Error(`Unknown input type "${type}"`);
}

var noDead; // Avoid dead code elimination.
Expand All @@ -46,7 +46,7 @@ function main({ type, n, method }) {
noDead = useWHATWG(n, input);
break;
default:
throw new Error('Unknown method');
throw new Error(`Unknown method ${method}`);
}

assert.ok(noDead);
Expand Down
4 changes: 2 additions & 2 deletions benchmark/url/legacy-vs-whatwg-url-searchparams-parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ function useWHATWG(n, input) {
function main({ type, n, method }) {
const input = inputs[type];
if (!input) {
throw new Error('Unknown input type');
throw new Error(`Unknown input type "${type}"`);
}

switch (method) {
Expand All @@ -42,6 +42,6 @@ function main({ type, n, method }) {
useWHATWG(n, input);
break;
default:
throw new Error('Unknown method');
throw new Error(`Unknown method ${method}`);
}
}
4 changes: 2 additions & 2 deletions benchmark/url/legacy-vs-whatwg-url-searchparams-serialize.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ function useWHATWG(n, input, prop) {
function main({ type, n, method }) {
const input = inputs[type];
if (!input) {
throw new Error('Unknown input type');
throw new Error(`Unknown input type "${type}"`);
}

switch (method) {
Expand All @@ -44,6 +44,6 @@ function main({ type, n, method }) {
useWHATWG(n, input);
break;
default:
throw new Error('Unknown method');
throw new Error(`Unknown method ${method}`);
}
}
4 changes: 2 additions & 2 deletions benchmark/url/legacy-vs-whatwg-url-serialize.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ function useWHATWG(n, input, prop) {
function main({ type, n, method }) {
const input = inputs[type];
if (!input) {
throw new Error('Unknown input type');
throw new Error(`Unknown input type "${type}"`);
}

var noDead; // Avoid dead code elimination.
Expand All @@ -48,7 +48,7 @@ function main({ type, n, method }) {
noDead = useWHATWG(n, input);
break;
default:
throw new Error('Unknown method');
throw new Error(`Unknown method ${method}`);
}

assert.ok(noDead);
Expand Down
2 changes: 1 addition & 1 deletion benchmark/url/url-searchparams-iteration.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,6 @@ function main({ method, n }) {
iterator(n);
break;
default:
throw new Error('Unknown method');
throw new Error(`Unknown method ${method}`);
}
}
41 changes: 5 additions & 36 deletions benchmark/url/url-searchparams-read.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,45 +10,14 @@ const bench = common.createBenchmark(main, {

const str = 'one=single&two=first&three=first&two=2nd&three=2nd&three=3rd';

function get(n, param) {
const params = new URLSearchParams(str);

bench.start();
for (var i = 0; i < n; i += 1)
params.get(param);
bench.end(n);
}

function getAll(n, param) {
const params = new URLSearchParams(str);

bench.start();
for (var i = 0; i < n; i += 1)
params.getAll(param);
bench.end(n);
}

function has(n, param) {
function main({ method, param, n }) {
const params = new URLSearchParams(str);
const fn = params[method];
if (!fn)
throw new Error(`Unknown method ${method}`);

bench.start();
for (var i = 0; i < n; i += 1)
params.has(param);
fn(param);
bench.end(n);
}

function main({ method, param, n }) {
switch (method) {
case 'get':
get(n, param);
break;
case 'getAll':
getAll(n, param);
break;
case 'has':
has(n, param);
break;
default:
throw new Error('Unknown method');
}
}
3 changes: 1 addition & 2 deletions benchmark/url/url-searchparams-sort.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,8 @@ function main({ type, n }) {
const params = new URLSearchParams();
const array = getParams(input);

var i;
bench.start();
for (i = 0; i < n; i++) {
for (var i = 0; i < n; i++) {
params[searchParams] = array.slice();
params.sort();
}
Expand Down

0 comments on commit 76cb958

Please sign in to comment.