Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'benchmark/url/url-searchparams-read.js')
-rw-r--r--benchmark/url/url-searchparams-read.js58
1 files changed, 58 insertions, 0 deletions
diff --git a/benchmark/url/url-searchparams-read.js b/benchmark/url/url-searchparams-read.js
new file mode 100644
index 00000000000..4cee49c74d2
--- /dev/null
+++ b/benchmark/url/url-searchparams-read.js
@@ -0,0 +1,58 @@
+'use strict';
+const common = require('../common.js');
+const URLSearchParams = new (require('url').URL)('a:').searchParams.constructor;
+
+const bench = common.createBenchmark(main, {
+ method: ['get', 'getAll', 'has'],
+ param: ['one', 'two', 'three', 'nonexistent'],
+ n: [1e6]
+});
+
+const str = 'one=single&two=first&three=first&two=2nd&three=2nd&three=3rd';
+
+function get(n, param) {
+ const params = new URLSearchParams(str);
+
+ bench.start();
+ for (var i = 0; i < n; i += 1)
+ params.get(param);
+ bench.end(n);
+}
+
+function getAll(n, param) {
+ const params = new URLSearchParams(str);
+
+ bench.start();
+ for (var i = 0; i < n; i += 1)
+ params.getAll(param);
+ bench.end(n);
+}
+
+function has(n, param) {
+ const params = new URLSearchParams(str);
+
+ bench.start();
+ for (var i = 0; i < n; i += 1)
+ params.has(param);
+ bench.end(n);
+}
+
+function main(conf) {
+ const method = conf.method;
+ const param = conf.param;
+ const n = conf.n | 0;
+
+ switch (method) {
+ case 'get':
+ get(n, param);
+ break;
+ case 'getAll':
+ getAll(n, param);
+ break;
+ case 'has':
+ has(n, param);
+ break;
+ default:
+ throw new Error('Unknown method');
+ }
+}