Skip to content

Commit

Permalink
add benchmarks for url utils
Browse files Browse the repository at this point in the history
  • Loading branch information
aduh95 committed Dec 31, 2022
1 parent b2ab16c commit b8d193f
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions benchmark/url/whatwgurl-to-and-from-path.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,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);
}

0 comments on commit b8d193f

Please sign in to comment.