diff options
author | Joyee Cheung <joyeec9h3@gmail.com> | 2018-11-11 16:44:19 +0800 |
---|---|---|
committer | Joyee Cheung <joyeec9h3@gmail.com> | 2018-11-20 05:14:34 +0800 |
commit | a365bb9cb100514efc3f57f7fac03d0679f73ff5 (patch) | |
tree | 447ea47ec5cee90a2c326849328dee21ee6c25d0 /benchmark/url/legacy-vs-whatwg-url-parse.js | |
parent | 5f25dd1e2eaa73ffb0a51e6d5b5150bcd5d0447e (diff) | |
download | android-node-v8-a365bb9cb100514efc3f57f7fac03d0679f73ff5.tar.gz android-node-v8-a365bb9cb100514efc3f57f7fac03d0679f73ff5.tar.bz2 android-node-v8-a365bb9cb100514efc3f57f7fac03d0679f73ff5.zip |
benchmark: pre-generate data set for URL benchmarks
This patch:
- Introduces `common.bakeUrlData` which can be used to pre-generate
the data set for the URL benchmarks to loop through instead of
looping over a constant.
- Add the option to use WPT data in benchmarks for better diversity
in the input
- Add the option to benchmark URL parsing with base URLs (whatwg only)
- Moves the data in `benchmark/fixtures/url-inputs.js` to
`benchmark/common.js`
PR-URL: https://github.com/nodejs/node/pull/24302
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'benchmark/url/legacy-vs-whatwg-url-parse.js')
-rw-r--r-- | benchmark/url/legacy-vs-whatwg-url-parse.js | 58 |
1 files changed, 36 insertions, 22 deletions
diff --git a/benchmark/url/legacy-vs-whatwg-url-parse.js b/benchmark/url/legacy-vs-whatwg-url-parse.js index 2be55e17cc..e4af2e0b7c 100644 --- a/benchmark/url/legacy-vs-whatwg-url-parse.js +++ b/benchmark/url/legacy-vs-whatwg-url-parse.js @@ -3,47 +3,61 @@ const common = require('../common.js'); const url = require('url'); const URL = url.URL; const assert = require('assert'); -const inputs = require('../fixtures/url-inputs.js').urls; const bench = common.createBenchmark(main, { - type: Object.keys(inputs), - method: ['legacy', 'whatwg'], - n: [1e5] + withBase: ['true', 'false'], + type: common.urlDataTypes, + e: [1], + method: ['legacy', 'whatwg'] }); -function useLegacy(n, input) { - var noDead = url.parse(input); +function useLegacy(data) { + const len = data.length; + var result = url.parse(data[0]); // avoid dead code elimination bench.start(); - for (var i = 0; i < n; i += 1) { - noDead = url.parse(input); + for (var i = 0; i < len; ++i) { + result = url.parse(data[i]); } - bench.end(n); - return noDead; + bench.end(len); + return result; } -function useWHATWG(n, input) { - var noDead = new URL(input); +function useWHATWGWithBase(data) { + const len = data.length; + var result = new URL(data[0][0], data[0][1]); // avoid dead code elimination bench.start(); - for (var i = 0; i < n; i += 1) { - noDead = new URL(input); + for (var i = 0; i < len; ++i) { + const item = data[i]; + result = new URL(item[0], item[1]); } - bench.end(n); - return noDead; + bench.end(len); + return result; } -function main({ type, n, method }) { - const input = inputs[type]; - if (!input) { - throw new Error(`Unknown input type "${type}"`); +function useWHATWGWithoutBase(data) { + const len = data.length; + var result = new URL(data[0]); // avoid dead code elimination + bench.start(); + for (var i = 0; i < len; ++i) { + result = new URL(data[i]); } + bench.end(len); + return result; +} +function main({ e, method, type, withBase }) { + e = +e; + withBase = withBase === 'true'; var noDead; // Avoid dead code elimination. + var data; switch (method) { case 'legacy': - noDead = useLegacy(n, input); + data = common.bakeUrlData(type, e, false, false); + noDead = useLegacy(data); break; case 'whatwg': - noDead = useWHATWG(n, input); + data = common.bakeUrlData(type, e, withBase, false); + noDead = withBase ? useWHATWGWithBase(data) : useWHATWGWithoutBase(data); break; default: throw new Error(`Unknown method ${method}`); |