Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 94985df

Browse filesBrowse files
injunchoi98RafaelGSS
authored andcommitted
benchmark: fix benchmark for file path and URL conversion
PR-URL: #54190 Reviewed-By: Daeyeon Jeong <daeyeon.dev@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
1 parent 72c554a commit 94985df
Copy full SHA for 94985df

File tree

Expand file treeCollapse file tree

1 file changed

+37
-19
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+37
-19
lines changed
Open diff view settings
Collapse file

‎benchmark/url/whatwg-url-to-and-from-path.js‎

Copy file name to clipboardExpand all lines: benchmark/url/whatwg-url-to-and-from-path.js
+37-19Lines changed: 37 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,46 @@ const common = require('../common.js');
33
const { fileURLToPath, pathToFileURL } = require('node:url');
44
const isWindows = process.platform === 'win32';
55

6-
const 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-
});
6+
const inputs = isWindows ? [
7+
'C:\\foo',
8+
'C:\\Program Files\\Music\\Web Sys\\main.html?REQUEST=RADIO',
9+
'\\\\nas\\My Docs\\File.doc',
10+
'\\\\?\\UNC\\server\\share\\folder\\file.txt',
11+
'file:///C:/foo',
12+
'file:///C:/dir/foo?query=1',
13+
'file:///C:/dir/foo#fragment',
14+
] : [
15+
'/dev/null',
16+
'/dev/null?key=param&bool',
17+
'/dev/null?key=param&bool#hash',
18+
'file:///dev/null',
19+
'file:///dev/null?key=param&bool',
20+
'file:///dev/null?key=param&bool#hash',
21+
];
2222

23-
function main({ n, input, method }) {
24-
method = method === 'fileURLOrPath' ? fileURLToPath : pathToFileURL;
23+
const bench = common.createBenchmark(
24+
main,
25+
{
26+
method: ['pathToFileURL', 'fileURLToPath'],
27+
input: Object.values(inputs),
28+
n: [5e6],
29+
},
30+
{
31+
combinationFilter: (p) => (
32+
(isWindows ?
33+
(!p.input.startsWith('file://') && p.method === 'pathToFileURL') :
34+
p.method === 'pathToFileURL'
35+
) ||
36+
(p.input.startsWith('file://') && p.method === 'fileURLToPath')
37+
),
38+
},
39+
);
40+
41+
function main({ method, input, n }) {
42+
const methodFunc = method === 'fileURLToPath' ? fileURLToPath : pathToFileURL;
2543
bench.start();
2644
for (let i = 0; i < n; i++) {
27-
method(input);
45+
methodFunc(input);
2846
}
2947
bench.end(n);
3048
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.