2016-11-25 00:55:56 +01:00
|
|
|
'use strict';
|
|
|
|
const common = require('../common.js');
|
2017-02-02 00:59:16 +01:00
|
|
|
const { URLSearchParams } = require('url');
|
2016-11-25 00:55:56 +01:00
|
|
|
|
|
|
|
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');
|
|
|
|
}
|
|
|
|
}
|