• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2const common = require('../common.js');
3const url = require('url');
4
5const inputs = {
6  slashes: { slashes: true, host: 'localhost' },
7  file: { protocol: 'file:', pathname: '/foo' },
8};
9
10const bench = common.createBenchmark(main, {
11  type: Object.keys(inputs),
12  n: [25e6],
13});
14
15function main({ type, n }) {
16  const input = inputs[type];
17
18  // Force-optimize url.format() so that the benchmark doesn't get
19  // disrupted by the optimizer kicking in halfway through.
20  for (const name in inputs)
21    url.format(inputs[name]);
22
23  bench.start();
24  for (let i = 0; i < n; i += 1)
25    url.format(input);
26  bench.end(n);
27}
28