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 f6713bf

Browse filesBrowse files
trevnorriscjihrig
authored andcommitted
bench: add bench for fs.realpath() fix
The benchmarks included also work for the previous JS implementation of fs.realpath(). In case the new implementation of realpath() needs to be reverted, we want these changes to stick around. PR-URL: #7899 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
1 parent 18a3064 commit f6713bf
Copy full SHA for f6713bf

File tree

Expand file treeCollapse file tree

2 files changed

+85
-0
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+85
-0
lines changed
Open diff view settings
Collapse file

‎benchmark/fs/bench-realpath.js‎

Copy file name to clipboard
+46Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
'use strict';
2+
3+
const common = require('../common');
4+
const fs = require('fs');
5+
const path = require('path');
6+
const resolved_path = path.resolve(__dirname, '../../lib/');
7+
const relative_path = path.relative(__dirname, '../../lib/');
8+
9+
const bench = common.createBenchmark(main, {
10+
n: [1e4],
11+
type: ['relative', 'resolved'],
12+
});
13+
14+
15+
function main(conf) {
16+
const n = conf.n >>> 0;
17+
const type = conf.type;
18+
19+
bench.start();
20+
if (type === 'relative')
21+
relativePath(n);
22+
else if (type === 'resolved')
23+
resolvedPath(n);
24+
else
25+
throw new Error('unknown "type": ' + type);
26+
}
27+
28+
function relativePath(n) {
29+
(function r(cntr) {
30+
if (--cntr <= 0)
31+
return bench.end(n);
32+
fs.realpath(relative_path, function() {
33+
r(cntr);
34+
});
35+
}(n));
36+
}
37+
38+
function resolvedPath(n) {
39+
(function r(cntr) {
40+
if (--cntr <= 0)
41+
return bench.end(n);
42+
fs.realpath(resolved_path, function() {
43+
r(cntr);
44+
});
45+
}(n));
46+
}
Collapse file

‎benchmark/fs/bench-realpathSync.js‎

Copy file name to clipboard
+39Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
'use strict';
2+
3+
const common = require('../common');
4+
const fs = require('fs');
5+
const path = require('path');
6+
const resolved_path = path.resolve(__dirname, '../../lib/');
7+
const relative_path = path.relative(__dirname, '../../lib/');
8+
9+
const bench = common.createBenchmark(main, {
10+
n: [1e4],
11+
type: ['relative', 'resolved'],
12+
});
13+
14+
15+
function main(conf) {
16+
const n = conf.n >>> 0;
17+
const type = conf.type;
18+
19+
bench.start();
20+
if (type === 'relative')
21+
relativePath(n);
22+
else if (type === 'resolved')
23+
resolvedPath(n);
24+
else
25+
throw new Error('unknown "type": ' + type);
26+
bench.end(n);
27+
}
28+
29+
function relativePath(n) {
30+
for (var i = 0; i < n; i++) {
31+
fs.realpathSync(relative_path);
32+
}
33+
}
34+
35+
function resolvedPath(n) {
36+
for (var i = 0; i < n; i++) {
37+
fs.realpathSync(resolved_path);
38+
}
39+
}

0 commit comments

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