summaryrefslogtreecommitdiff
path: root/benchmark/url/whatwg-url-to-and-from-path.js
blob: 3b87c0670a8fee70cf3918a78fd32ebbe3f94523 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
'use strict';
const common = require('../common.js');
const { fileURLToPath, pathToFileURL } = require('node:url');
const isWindows = process.platform === 'win32';

const bench = common.createBenchmark(main, {
  input: isWindows ? [
    'file:///c/',
  ] : [
    'file:///dev/null',
    'file:///dev/null?key=param&bool',
    'file:///dev/null?key=param&bool#hash',
  ],
  method: isWindows ? [
    'fileURLToPath',
  ] : [
    'fileURLToPath',
    'pathToFileURL',
  ],
  n: [5e6],
});

function main({ n, input, method }) {
  method = method === 'fileURLOrPath' ? fileURLToPath : pathToFileURL;
  bench.start();
  for (let i = 0; i < n; i++) {
    method(input);
  }
  bench.end(n);
}