Skip to content

Commit

Permalink
benchmark: (url) refactor
Browse files Browse the repository at this point in the history
PR-URL: nodejs#18320
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information
BridgeAR authored and ryzokuken committed Jun 6, 2018
1 parent e4e3490 commit ecb3fd5
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 53 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 @@ -78,7 +78,7 @@ function main(conf) {

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 @@ -90,7 +90,7 @@ function main(conf) {
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 @@ -38,7 +38,7 @@ function main(conf) {

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 @@ -50,7 +50,7 @@ function main(conf) {
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 @@ -35,7 +35,7 @@ function main(conf) {

const input = inputs[type];
if (!input) {
throw new Error('Unknown input type');
throw new Error(`Unknown input type "${type}"`);
}

switch (method) {
Expand All @@ -46,6 +46,6 @@ function main(conf) {
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 @@ -37,7 +37,7 @@ function main(conf) {

const input = inputs[type];
if (!input) {
throw new Error('Unknown input type');
throw new Error(`Unknown input type "${type}"`);
}

switch (method) {
Expand All @@ -48,6 +48,6 @@ function main(conf) {
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 @@ -40,7 +40,7 @@ function main(conf) {

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 @@ -52,7 +52,7 @@ function main(conf) {
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 @@ -56,6 +56,6 @@ function main(conf) {
iterator(n);
break;
default:
throw new Error('Unknown method');
throw new Error(`Unknown method ${method}`);
}
}
45 changes: 5 additions & 40 deletions benchmark/url/url-searchparams-read.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,49 +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) {
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.get(param);
fn(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) {
const params = new URLSearchParams(str);

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

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

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 @@ -38,9 +38,8 @@ function main(conf) {
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 ecb3fd5

Please sign in to comment.