From aa47fe0ef95e8179cca8ca360b94dc9c68f46fa6 Mon Sep 17 00:00:00 2001 From: Ruben Bridgewater Date: Sat, 30 Dec 2017 03:54:51 +0100 Subject: [PATCH] benchmark: (url) use destructuring PR-URL: https://github.com/nodejs/node/pull/18250 Reviewed-By: Matteo Collina Reviewed-By: James M Snell --- benchmark/url/legacy-vs-whatwg-url-get-prop.js | 6 +----- benchmark/url/legacy-vs-whatwg-url-parse.js | 6 +----- benchmark/url/legacy-vs-whatwg-url-searchparams-parse.js | 6 +----- .../url/legacy-vs-whatwg-url-searchparams-serialize.js | 6 +----- benchmark/url/legacy-vs-whatwg-url-serialize.js | 6 +----- benchmark/url/url-format.js | 5 +---- benchmark/url/url-resolve.js | 9 ++++----- benchmark/url/url-searchparams-iteration.js | 5 +---- benchmark/url/url-searchparams-read.js | 6 +----- benchmark/url/url-searchparams-sort.js | 5 ++--- benchmark/url/usvstring.js | 5 ++--- benchmark/url/whatwg-url-idna.js | 8 +++----- benchmark/url/whatwg-url-properties.js | 8 +++----- 13 files changed, 22 insertions(+), 59 deletions(-) diff --git a/benchmark/url/legacy-vs-whatwg-url-get-prop.js b/benchmark/url/legacy-vs-whatwg-url-get-prop.js index 229a4e60652b64..93603c258cf1f2 100644 --- a/benchmark/url/legacy-vs-whatwg-url-get-prop.js +++ b/benchmark/url/legacy-vs-whatwg-url-get-prop.js @@ -71,11 +71,7 @@ function useWHATWG(n, input) { return noDead; } -function main(conf) { - const type = conf.type; - const n = conf.n | 0; - const method = conf.method; - +function main({ type, n, method }) { const input = inputs[type]; if (!input) { throw new Error('Unknown input type'); diff --git a/benchmark/url/legacy-vs-whatwg-url-parse.js b/benchmark/url/legacy-vs-whatwg-url-parse.js index ec386b7b85597d..da42d5a189af47 100644 --- a/benchmark/url/legacy-vs-whatwg-url-parse.js +++ b/benchmark/url/legacy-vs-whatwg-url-parse.js @@ -31,11 +31,7 @@ function useWHATWG(n, input) { return noDead; } -function main(conf) { - const type = conf.type; - const n = conf.n | 0; - const method = conf.method; - +function main({ type, n, method }) { const input = inputs[type]; if (!input) { throw new Error('Unknown input type'); diff --git a/benchmark/url/legacy-vs-whatwg-url-searchparams-parse.js b/benchmark/url/legacy-vs-whatwg-url-searchparams-parse.js index b4a80af4e5eabd..51953ec8707374 100644 --- a/benchmark/url/legacy-vs-whatwg-url-searchparams-parse.js +++ b/benchmark/url/legacy-vs-whatwg-url-searchparams-parse.js @@ -28,11 +28,7 @@ function useWHATWG(n, input) { bench.end(n); } -function main(conf) { - const type = conf.type; - const n = conf.n | 0; - const method = conf.method; - +function main({ type, n, method }) { const input = inputs[type]; if (!input) { throw new Error('Unknown input type'); diff --git a/benchmark/url/legacy-vs-whatwg-url-searchparams-serialize.js b/benchmark/url/legacy-vs-whatwg-url-searchparams-serialize.js index 2b8d2c36a810b3..3490782a1bf421 100644 --- a/benchmark/url/legacy-vs-whatwg-url-searchparams-serialize.js +++ b/benchmark/url/legacy-vs-whatwg-url-searchparams-serialize.js @@ -30,11 +30,7 @@ function useWHATWG(n, input, prop) { bench.end(n); } -function main(conf) { - const type = conf.type; - const n = conf.n | 0; - const method = conf.method; - +function main({ type, n, method }) { const input = inputs[type]; if (!input) { throw new Error('Unknown input type'); diff --git a/benchmark/url/legacy-vs-whatwg-url-serialize.js b/benchmark/url/legacy-vs-whatwg-url-serialize.js index 35b459a10c0e0b..e92b941b5d57e5 100644 --- a/benchmark/url/legacy-vs-whatwg-url-serialize.js +++ b/benchmark/url/legacy-vs-whatwg-url-serialize.js @@ -33,11 +33,7 @@ function useWHATWG(n, input, prop) { return noDead; } -function main(conf) { - const type = conf.type; - const n = conf.n | 0; - const method = conf.method; - +function main({ type, n, method }) { const input = inputs[type]; if (!input) { throw new Error('Unknown input type'); diff --git a/benchmark/url/url-format.js b/benchmark/url/url-format.js index dc8e020879e400..14696af8e31c3f 100644 --- a/benchmark/url/url-format.js +++ b/benchmark/url/url-format.js @@ -12,10 +12,7 @@ const bench = common.createBenchmark(main, { n: [25e6] }); -function main(conf) { - const type = conf.type; - const n = conf.n | 0; - +function main({ type, n }) { const input = inputs[type] || ''; // Force-optimize url.format() so that the benchmark doesn't get diff --git a/benchmark/url/url-resolve.js b/benchmark/url/url-resolve.js index 421a70ef6d59f1..48978574ea24ec 100644 --- a/benchmark/url/url-resolve.js +++ b/benchmark/url/url-resolve.js @@ -18,13 +18,12 @@ const bench = common.createBenchmark(main, { n: [1e5] }); -function main(conf) { - const n = conf.n | 0; - const href = hrefs[conf.href]; - const path = paths[conf.path]; +function main({ n, href, path }) { + const h = hrefs[href]; + const p = paths[path]; bench.start(); for (var i = 0; i < n; i += 1) - url.resolve(href, path); + url.resolve(h, p); bench.end(n); } diff --git a/benchmark/url/url-searchparams-iteration.js b/benchmark/url/url-searchparams-iteration.js index 0f4b71a0a183dd..2b13992bdfcfc0 100644 --- a/benchmark/url/url-searchparams-iteration.js +++ b/benchmark/url/url-searchparams-iteration.js @@ -44,10 +44,7 @@ function iterator(n) { assert.strictEqual(noDead[1], '3rd'); } -function main(conf) { - const method = conf.method; - const n = conf.n | 0; - +function main({ method, n }) { switch (method) { case 'forEach': forEach(n); diff --git a/benchmark/url/url-searchparams-read.js b/benchmark/url/url-searchparams-read.js index 762ffcca03d69d..29235ee81e0e14 100644 --- a/benchmark/url/url-searchparams-read.js +++ b/benchmark/url/url-searchparams-read.js @@ -37,11 +37,7 @@ function has(n, param) { bench.end(n); } -function main(conf) { - const method = conf.method; - const param = conf.param; - const n = conf.n | 0; - +function main({ method, param, n }) { switch (method) { case 'get': get(n, param); diff --git a/benchmark/url/url-searchparams-sort.js b/benchmark/url/url-searchparams-sort.js index 677ce511cf3ea2..524dacb6d52dc4 100644 --- a/benchmark/url/url-searchparams-sort.js +++ b/benchmark/url/url-searchparams-sort.js @@ -31,10 +31,9 @@ const bench = common.createBenchmark(main, { flags: ['--expose-internals'] }); -function main(conf) { +function main({ type, n }) { const searchParams = require('internal/url').searchParamsSymbol; - const input = inputs[conf.type]; - const n = conf.n | 0; + const input = inputs[type]; const params = new URLSearchParams(); const array = getParams(input); diff --git a/benchmark/url/usvstring.js b/benchmark/url/usvstring.js index 40a945037385cf..91abe8d67351c7 100644 --- a/benchmark/url/usvstring.js +++ b/benchmark/url/usvstring.js @@ -16,10 +16,9 @@ const bench = common.createBenchmark(main, { flags: ['--expose-internals'] }); -function main(conf) { +function main({ input, n }) { const { toUSVString } = require('internal/url'); - const str = inputs[conf.input]; - const n = conf.n | 0; + const str = inputs[input]; bench.start(); for (var i = 0; i < n; i++) diff --git a/benchmark/url/whatwg-url-idna.js b/benchmark/url/whatwg-url-idna.js index 3d0ea3dc8fe516..c1e3d4a0b85cec 100644 --- a/benchmark/url/whatwg-url-idna.js +++ b/benchmark/url/whatwg-url-idna.js @@ -31,15 +31,13 @@ const bench = common.createBenchmark(main, { n: [5e6] }); -function main(conf) { - const n = conf.n | 0; - const to = conf.to; - const input = inputs[conf.input][to]; +function main({ n, to, input }) { + const value = inputs[input][to]; const method = to === 'ascii' ? domainToASCII : domainToUnicode; bench.start(); for (var i = 0; i < n; i++) { - method(input); + method(value); } bench.end(n); } diff --git a/benchmark/url/whatwg-url-properties.js b/benchmark/url/whatwg-url-properties.js index 3a865d2335ab3c..f526c07f139be9 100644 --- a/benchmark/url/whatwg-url-properties.js +++ b/benchmark/url/whatwg-url-properties.js @@ -46,11 +46,9 @@ function getAlternative(prop) { return alternatives[prop]; } -function main(conf) { - const n = conf.n | 0; - const input = inputs[conf.input]; - const url = new URL(input); - const prop = conf.prop; +function main({ n, input, prop }) { + const value = inputs[input]; + const url = new URL(value); switch (prop) { case 'protocol':