Skip to content

Commit dde0cff

Browse files
authored
benchmark: add toNamespacedPath bench
PR-URL: #52236 Reviewed-By: Yagiz Nizipli <yagiz.nizipli@sentry.io> Reviewed-By: Vinícius Lourenço Claro Cardoso <contact@viniciusl.com.br> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
1 parent 511be6c commit dde0cff

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed
+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
'use strict';
2+
const common = require('../common.js');
3+
const { posix } = require('path');
4+
const assert = require('assert');
5+
6+
const bench = common.createBenchmark(main, {
7+
path: [
8+
'',
9+
'.',
10+
'/tmp/bar',
11+
'/home/node/..',
12+
posix.join(__dirname, '/..'),
13+
'bar/baz',
14+
],
15+
n: [1e5],
16+
});
17+
18+
function main({ n, path }) {
19+
bench.start();
20+
let a;
21+
for (let i = 0; i < n; i++) {
22+
a = posix.toNamespacedPath(path);
23+
}
24+
bench.end(n);
25+
assert.ok(a + 'a');
26+
}
+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
'use strict';
2+
const common = require('../common.js');
3+
const { win32 } = require('path');
4+
const assert = require('assert');
5+
6+
const bench = common.createBenchmark(main, {
7+
path: [
8+
'',
9+
'c:/ignore',
10+
'd:\\a/b\\c/d',
11+
'\\e.exe',
12+
'c:/blah\\blah',
13+
'd:/games',
14+
'c:../a',
15+
win32.join(__dirname, '/..'),
16+
],
17+
n: [1e5],
18+
});
19+
20+
function main({ n, path }) {
21+
bench.start();
22+
let a;
23+
for (let i = 0; i < n; i++) {
24+
a = win32.toNamespacedPath(path);
25+
}
26+
bench.end(n);
27+
assert.ok(a + 'a');
28+
}

0 commit comments

Comments
 (0)