diff options
Diffstat (limited to 'benchmark/url/legacy-vs-whatwg-url-get-prop.js')
-rw-r--r-- | benchmark/url/legacy-vs-whatwg-url-get-prop.js | 44 |
1 files changed, 21 insertions, 23 deletions
diff --git a/benchmark/url/legacy-vs-whatwg-url-get-prop.js b/benchmark/url/legacy-vs-whatwg-url-get-prop.js index 2cc3ab8c75e..59bb4724f42 100644 --- a/benchmark/url/legacy-vs-whatwg-url-get-prop.js +++ b/benchmark/url/legacy-vs-whatwg-url-get-prop.js @@ -3,20 +3,15 @@ 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), + type: common.urlDataTypes, method: ['legacy', 'whatwg'], - n: [1e5] + e: [1] }); -// At the time of writing, when using a passed property name to index -// the object, Crankshaft would generate a LoadKeyedGeneric even when it -// remains a constant in the function, so here we must use the literal -// instead to get a LoadNamedField. -function useLegacy(n, input) { - const obj = url.parse(input); +function useLegacy(data) { + const obj = url.parse(data[0]); const noDead = { protocol: obj.protocol, auth: obj.auth, @@ -27,10 +22,12 @@ function useLegacy(n, input) { search: obj.search, hash: obj.hash }; + const len = data.length; // It's necessary to assign the values to an object // to avoid loop invariant code motion. bench.start(); - for (var i = 0; i < n; i += 1) { + for (var i = 0; i < len; i++) { + const obj = data[i]; noDead.protocol = obj.protocol; noDead.auth = obj.auth; noDead.host = obj.host; @@ -40,12 +37,12 @@ function useLegacy(n, input) { noDead.search = obj.search; noDead.hash = obj.hash; } - bench.end(n); + bench.end(len); return noDead; } -function useWHATWG(n, input) { - const obj = new URL(input); +function useWHATWG(data) { + const obj = new URL(data[0]); const noDead = { protocol: obj.protocol, auth: `${obj.username}:${obj.password}`, @@ -56,8 +53,10 @@ function useWHATWG(n, input) { search: obj.search, hash: obj.hash }; + const len = data.length; bench.start(); - for (var i = 0; i < n; i += 1) { + for (var i = 0; i < len; i++) { + const obj = data[i]; noDead.protocol = obj.protocol; noDead.auth = `${obj.username}:${obj.password}`; noDead.host = obj.host; @@ -67,23 +66,22 @@ function useWHATWG(n, input) { noDead.search = obj.search; noDead.hash = obj.hash; } - bench.end(n); + bench.end(len); return noDead; } -function main({ type, n, method }) { - const input = inputs[type]; - if (!input) { - throw new Error(`Unknown input type "${type}"`); - } - +function main({ type, method, e }) { + e = +e; + var data; var noDead; // Avoid dead code elimination. switch (method) { case 'legacy': - noDead = useLegacy(n, input); + data = common.bakeUrlData(type, e, false, false); + noDead = useLegacy(data.map((i) => url.parse(i))); break; case 'whatwg': - noDead = useWHATWG(n, input); + data = common.bakeUrlData(type, e, false, true); + noDead = useWHATWG(data); break; default: throw new Error(`Unknown method "${method}"`); |