diff options
author | Joyee Cheung <joyeec9h3@gmail.com> | 2017-02-09 23:41:42 +0800 |
---|---|---|
committer | James M Snell <jasnell@gmail.com> | 2017-02-15 09:12:25 -0800 |
commit | d8ac08a62a44c07fd4b46276ba2365870654a3b5 (patch) | |
tree | d2d5544354577600a9467ef9b1cedd0f9a71c266 /benchmark/url | |
parent | e571fd4f6ccadd9e77095ca0377a9b07f49bc56b (diff) | |
download | android-node-v8-d8ac08a62a44c07fd4b46276ba2365870654a3b5.tar.gz android-node-v8-d8ac08a62a44c07fd4b46276ba2365870654a3b5.tar.bz2 android-node-v8-d8ac08a62a44c07fd4b46276ba2365870654a3b5.zip |
benchmark: refactor whatwg-url-properties
PR-URL: https://github.com/nodejs/node/pull/11264
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Brian White <mscdex@mscdex.net>
Diffstat (limited to 'benchmark/url')
-rw-r--r-- | benchmark/url/whatwg-url-properties.js | 34 |
1 files changed, 9 insertions, 25 deletions
diff --git a/benchmark/url/whatwg-url-properties.js b/benchmark/url/whatwg-url-properties.js index 375939c601..9bdc9778a8 100644 --- a/benchmark/url/whatwg-url-properties.js +++ b/benchmark/url/whatwg-url-properties.js @@ -1,16 +1,11 @@ 'use strict'; +const common = require('../common.js'); +const URL = require('url').URL; +const inputs = require('../fixtures/url-inputs.js').urls; -var common = require('../common.js'); -var URL = require('url').URL; - -var bench = common.createBenchmark(main, { - url: [ - 'http://example.com/', - 'https://encrypted.google.com/search?q=url&q=site:npmjs.org&hl=en', - 'javascript:alert("node is awesome");', - 'http://user:pass@foo.bar.com:21/aaa/zzz?l=24#test' - ], - prop: ['toString', 'href', 'origin', 'protocol', +const bench = common.createBenchmark(main, { + input: Object.keys(inputs), + prop: ['href', 'origin', 'protocol', 'username', 'password', 'host', 'hostname', 'port', 'pathname', 'search', 'searchParams', 'hash'], n: [1e4] @@ -34,14 +29,6 @@ function get(n, url, prop) { bench.end(n); } -function stringify(n, url, prop) { - bench.start(); - for (var i = 0; i < n; i += 1) { - url.toString(); - } - bench.end(n); -} - const alternatives = { href: 'http://user:pass@foo.bar.com:21/aaa/zzz?l=25#test', protocol: 'https:', @@ -61,7 +48,8 @@ function getAlternative(prop) { function main(conf) { const n = conf.n | 0; - const url = new URL(conf.url); + const input = inputs[conf.input]; + const url = new URL(input); const prop = conf.prop; switch (prop) { @@ -74,17 +62,13 @@ function main(conf) { case 'pathname': case 'search': case 'hash': + case 'href': setAndGet(n, url, prop, getAlternative(prop)); break; - // TODO: move href to the first group when the setter lands. - case 'href': case 'origin': case 'searchParams': get(n, url, prop); break; - case 'toString': - stringify(n, url); - break; default: throw new Error('Unknown prop'); } |