• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2const common = require('../common.js');
3const querystring = require('querystring');
4const inputs = common.searchParams;
5
6const bench = common.createBenchmark(main, {
7  type: Object.keys(inputs),
8  n: [1e6],
9});
10
11function main({ type, n }) {
12  const input = inputs[type];
13
14  // Execute the function a "sufficient" number of times before the timed
15  // loop to ensure the function is optimized just once.
16  if (type === 'multicharsep') {
17    for (let i = 0; i < n; i += 1)
18      querystring.parse(input, '&&&&&&&&&&');
19
20    bench.start();
21    for (let i = 0; i < n; i += 1)
22      querystring.parse(input, '&&&&&&&&&&');
23    bench.end(n);
24  } else {
25    for (let i = 0; i < n; i += 1)
26      querystring.parse(input);
27
28    bench.start();
29    for (let i = 0; i < n; i += 1)
30      querystring.parse(input);
31    bench.end(n);
32  }
33}
34