diff --git a/benchmark/url/legacy-vs-whatwg-url-searchparams-parse.js b/benchmark/url/legacy-vs-whatwg-url-searchparams-parse.js index e915ceb54f917f..6b054d0b2a1f1a 100644 --- a/benchmark/url/legacy-vs-whatwg-url-searchparams-parse.js +++ b/benchmark/url/legacy-vs-whatwg-url-searchparams-parse.js @@ -2,10 +2,10 @@ const common = require('../common.js'); const { URLSearchParams } = require('url'); const querystring = require('querystring'); -const inputs = require('../fixtures/url-inputs.js').searchParams; +const searchParams = require('../fixtures/url-inputs.js').searchParams; const bench = common.createBenchmark(main, { - type: Object.keys(inputs), + searchParam: Object.keys(searchParams), method: ['legacy', 'whatwg'], n: [1e6] }); @@ -19,27 +19,27 @@ function useLegacy(n, input) { bench.end(n); } -function useWHATWG(n, input) { - new URLSearchParams(input); +function useWHATWG(n, param) { + new URLSearchParams(param); bench.start(); for (var i = 0; i < n; i += 1) { - new URLSearchParams(input); + new URLSearchParams(param); } bench.end(n); } -function main({ type, n, method }) { - const input = inputs[type]; - if (!input) { - throw new Error(`Unknown input type "${type}"`); +function main({ searchParam, n, method }) { + const param = searchParams[searchParam]; + if (!param) { + throw new Error(`Unknown search parameter type "${searchParam}"`); } switch (method) { case 'legacy': - useLegacy(n, input); + useLegacy(n, param); break; case 'whatwg': - useWHATWG(n, input); + useWHATWG(n, param); break; default: throw new Error(`Unknown method ${method}`); diff --git a/benchmark/url/legacy-vs-whatwg-url-searchparams-serialize.js b/benchmark/url/legacy-vs-whatwg-url-searchparams-serialize.js index 8fe3e546f0780d..54fdd956544886 100644 --- a/benchmark/url/legacy-vs-whatwg-url-searchparams-serialize.js +++ b/benchmark/url/legacy-vs-whatwg-url-searchparams-serialize.js @@ -2,10 +2,10 @@ const common = require('../common.js'); const { URLSearchParams } = require('url'); const querystring = require('querystring'); -const inputs = require('../fixtures/url-inputs.js').searchParams; +const searchParams = require('../fixtures/url-inputs.js').searchParams; const bench = common.createBenchmark(main, { - type: Object.keys(inputs), + searchParam: Object.keys(searchParams), method: ['legacy', 'whatwg'], n: [1e6] }); @@ -20,8 +20,8 @@ function useLegacy(n, input, prop) { bench.end(n); } -function useWHATWG(n, input, prop) { - const obj = new URLSearchParams(input); +function useWHATWG(n, param, prop) { + const obj = new URLSearchParams(param); obj.toString(); bench.start(); for (var i = 0; i < n; i += 1) { @@ -30,18 +30,18 @@ function useWHATWG(n, input, prop) { bench.end(n); } -function main({ type, n, method }) { - const input = inputs[type]; - if (!input) { - throw new Error(`Unknown input type "${type}"`); +function main({ searchParam, n, method }) { + const param = searchParams[searchParam]; + if (!param) { + throw new Error(`Unknown search parameter type "${searchParam}"`); } switch (method) { case 'legacy': - useLegacy(n, input); + useLegacy(n, param); break; case 'whatwg': - useWHATWG(n, input); + useWHATWG(n, param); break; default: throw new Error(`Unknown method ${method}`); diff --git a/benchmark/url/url-searchparams-iteration.js b/benchmark/url/url-searchparams-iteration.js index cae2ef5df61956..244c95502bfffb 100644 --- a/benchmark/url/url-searchparams-iteration.js +++ b/benchmark/url/url-searchparams-iteration.js @@ -4,7 +4,7 @@ const assert = require('assert'); const { URLSearchParams } = require('url'); const bench = common.createBenchmark(main, { - method: ['forEach', 'iterator'], + loopMethod: ['forEach', 'iterator'], n: [1e6] }); @@ -44,8 +44,8 @@ function iterator(n) { assert.strictEqual(noDead[1], '3rd'); } -function main({ method, n }) { - switch (method) { +function main({ loopMethod, n }) { + switch (loopMethod) { case 'forEach': forEach(n); break; @@ -53,6 +53,6 @@ function main({ method, n }) { iterator(n); break; default: - throw new Error(`Unknown method ${method}`); + throw new Error(`Unknown method ${loopMethod}`); } } diff --git a/benchmark/url/url-searchparams-read.js b/benchmark/url/url-searchparams-read.js index 6b388f81153ea5..2eb0a4f21350dc 100644 --- a/benchmark/url/url-searchparams-read.js +++ b/benchmark/url/url-searchparams-read.js @@ -3,20 +3,20 @@ const common = require('../common.js'); const { URLSearchParams } = require('url'); const bench = common.createBenchmark(main, { - method: ['get', 'getAll', 'has'], + accessMethod: ['get', 'getAll', 'has'], param: ['one', 'two', 'three', 'nonexistent'], n: [2e7] }); const str = 'one=single&two=first&three=first&two=2nd&three=2nd&three=3rd'; -function main({ method, param, n }) { +function main({ accessMethod, param, n }) { const params = new URLSearchParams(str); - if (!params[method]) - throw new Error(`Unknown method ${method}`); + if (!params[accessMethod]) + throw new Error(`Unknown method ${accessMethod}`); bench.start(); for (var i = 0; i < n; i += 1) - params[method](param); + params[accessMethod](param); bench.end(n); } diff --git a/benchmark/url/whatwg-url-idna.js b/benchmark/url/whatwg-url-idna.js index c1e3d4a0b85cec..b67a08da7a88e0 100644 --- a/benchmark/url/whatwg-url-idna.js +++ b/benchmark/url/whatwg-url-idna.js @@ -2,7 +2,7 @@ const common = require('../common.js'); const { domainToASCII, domainToUnicode } = require('url'); -const inputs = { +const domains = { empty: { ascii: '', unicode: '' @@ -26,13 +26,13 @@ const inputs = { }; const bench = common.createBenchmark(main, { - input: Object.keys(inputs), + domain: Object.keys(domains), to: ['ascii', 'unicode'], n: [5e6] }); -function main({ n, to, input }) { - const value = inputs[input][to]; +function main({ n, to, domain }) { + const value = domains[domain][to]; const method = to === 'ascii' ? domainToASCII : domainToUnicode; bench.start(); diff --git a/test/parallel/test-benchmark-url.js b/test/parallel/test-benchmark-url.js index e69608cd3bf3e6..e4bcf5017004f4 100644 --- a/test/parallel/test-benchmark-url.js +++ b/test/parallel/test-benchmark-url.js @@ -4,4 +4,19 @@ require('../common'); const runBenchmark = require('../common/benchmark'); -runBenchmark('url', ['n=1'], { NODEJS_BENCHMARK_ZERO_ALLOWED: 1 }); +runBenchmark('url', + [ + 'method=legacy', + 'loopMethod=forEach', + 'accessMethod=get', + 'type=short', + 'searchParam=noencode', + 'href=short', + 'input=short', + 'domain=empty', + 'path=up', + 'to=ascii', + 'prop=href', + 'n=1', + ], + { NODEJS_BENCHMARK_ZERO_ALLOWED: 1 });