1'use strict'; 2const common = require('../common.js'); 3const { URLSearchParams } = require('url'); 4 5const bench = common.createBenchmark(main, { 6 accessMethod: ['get', 'getAll', 'has'], 7 param: ['one', 'two', 'three', 'nonexistent'], 8 n: [2e7] 9}); 10 11const str = 'one=single&two=first&three=first&two=2nd&three=2nd&three=3rd'; 12 13function main({ accessMethod, param, n }) { 14 const params = new URLSearchParams(str); 15 if (!params[accessMethod]) 16 throw new Error(`Unknown method ${accessMethod}`); 17 18 bench.start(); 19 for (let i = 0; i < n; i += 1) 20 params[accessMethod](param); 21 bench.end(n); 22} 23