Skip to content

Commit f6713bf

Browse 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 <[email protected]> Reviewed-By: Anna Henningsen <[email protected]>
1 parent 18a3064 commit f6713bf

File tree

2 files changed

+85
-0
lines changed

2 files changed

+85
-0
lines changed

‎benchmark/fs/bench-realpath.js‎

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

‎benchmark/fs/bench-realpathSync.js‎

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

0 commit comments

Comments
(0)