1'use strict';
2const common = require('../common.js');
3const { fileURLToPath, pathToFileURL } = require('node:url');
4const isWindows = process.platform === 'win32';
5
6const bench = common.createBenchmark(main, {
7  input: isWindows ? [
8    'file:///c/',
9  ] : [
10    'file:///dev/null',
11    'file:///dev/null?key=param&bool',
12    'file:///dev/null?key=param&bool#hash',
13  ],
14  method: isWindows ? [
15    'fileURLToPath',
16  ] : [
17    'fileURLToPath',
18    'pathToFileURL',
19  ],
20  n: [5e6],
21});
22
23function main({ n, input, method }) {
24  method = method === 'fileURLOrPath' ? fileURLToPath : pathToFileURL;
25  bench.start();
26  for (let i = 0; i < n; i++) {
27    method(input);
28  }
29  bench.end(n);
30}
31