Skip to content

Commit 76cb958

Browse files
BridgeARMylesBorins
authored andcommitted
benchmark: (url) refactor
PR-URL: #18320 Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 0851822 commit 76cb958

8 files changed

+17
-49
lines changed

benchmark/url/legacy-vs-whatwg-url-get-prop.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ function useWHATWG(n, input) {
7474
function main({ type, n, method }) {
7575
const input = inputs[type];
7676
if (!input) {
77-
throw new Error('Unknown input type');
77+
throw new Error(`Unknown input type "${type}"`);
7878
}
7979

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

9292
assert.ok(noDead);

benchmark/url/legacy-vs-whatwg-url-parse.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ function useWHATWG(n, input) {
3434
function main({ type, n, method }) {
3535
const input = inputs[type];
3636
if (!input) {
37-
throw new Error('Unknown input type');
37+
throw new Error(`Unknown input type "${type}"`);
3838
}
3939

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

5252
assert.ok(noDead);

benchmark/url/legacy-vs-whatwg-url-searchparams-parse.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ function useWHATWG(n, input) {
3131
function main({ type, n, method }) {
3232
const input = inputs[type];
3333
if (!input) {
34-
throw new Error('Unknown input type');
34+
throw new Error(`Unknown input type "${type}"`);
3535
}
3636

3737
switch (method) {
@@ -42,6 +42,6 @@ function main({ type, n, method }) {
4242
useWHATWG(n, input);
4343
break;
4444
default:
45-
throw new Error('Unknown method');
45+
throw new Error(`Unknown method ${method}`);
4646
}
4747
}

benchmark/url/legacy-vs-whatwg-url-searchparams-serialize.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ function useWHATWG(n, input, prop) {
3333
function main({ type, n, method }) {
3434
const input = inputs[type];
3535
if (!input) {
36-
throw new Error('Unknown input type');
36+
throw new Error(`Unknown input type "${type}"`);
3737
}
3838

3939
switch (method) {
@@ -44,6 +44,6 @@ function main({ type, n, method }) {
4444
useWHATWG(n, input);
4545
break;
4646
default:
47-
throw new Error('Unknown method');
47+
throw new Error(`Unknown method ${method}`);
4848
}
4949
}

benchmark/url/legacy-vs-whatwg-url-serialize.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ function useWHATWG(n, input, prop) {
3636
function main({ type, n, method }) {
3737
const input = inputs[type];
3838
if (!input) {
39-
throw new Error('Unknown input type');
39+
throw new Error(`Unknown input type "${type}"`);
4040
}
4141

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

5454
assert.ok(noDead);

benchmark/url/url-searchparams-iteration.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,6 @@ function main({ method, n }) {
5353
iterator(n);
5454
break;
5555
default:
56-
throw new Error('Unknown method');
56+
throw new Error(`Unknown method ${method}`);
5757
}
5858
}

benchmark/url/url-searchparams-read.js

+5-36
Original file line numberDiff line numberDiff line change
@@ -10,45 +10,14 @@ const bench = common.createBenchmark(main, {
1010

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

13-
function get(n, param) {
14-
const params = new URLSearchParams(str);
15-
16-
bench.start();
17-
for (var i = 0; i < n; i += 1)
18-
params.get(param);
19-
bench.end(n);
20-
}
21-
22-
function getAll(n, param) {
23-
const params = new URLSearchParams(str);
24-
25-
bench.start();
26-
for (var i = 0; i < n; i += 1)
27-
params.getAll(param);
28-
bench.end(n);
29-
}
30-
31-
function has(n, param) {
13+
function main({ method, param, n }) {
3214
const params = new URLSearchParams(str);
15+
const fn = params[method];
16+
if (!fn)
17+
throw new Error(`Unknown method ${method}`);
3318

3419
bench.start();
3520
for (var i = 0; i < n; i += 1)
36-
params.has(param);
21+
fn(param);
3722
bench.end(n);
3823
}
39-
40-
function main({ method, param, n }) {
41-
switch (method) {
42-
case 'get':
43-
get(n, param);
44-
break;
45-
case 'getAll':
46-
getAll(n, param);
47-
break;
48-
case 'has':
49-
has(n, param);
50-
break;
51-
default:
52-
throw new Error('Unknown method');
53-
}
54-
}

benchmark/url/url-searchparams-sort.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,8 @@ function main({ type, n }) {
3737
const params = new URLSearchParams();
3838
const array = getParams(input);
3939

40-
var i;
4140
bench.start();
42-
for (i = 0; i < n; i++) {
41+
for (var i = 0; i < n; i++) {
4342
params[searchParams] = array.slice();
4443
params.sort();
4544
}

0 commit comments

Comments
 (0)