Skip to content

Commit a3d0802

Browse files
addaleaxMylesBorins
authored andcommitted
benchmark: add benches for fs.stat & fs.statSync
Add very simple benchmarks for `fs.stat` and `fs.statSync` as well as `fs.lstat` and `fs.lstatSync` based on the `readdir` benchmarks. PR-URL: #8338 Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Brian White <[email protected]>
1 parent be9d9bd commit a3d0802

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

benchmark/fs/bench-stat.js

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
'use strict';
2+
3+
const common = require('../common');
4+
const fs = require('fs');
5+
6+
const bench = common.createBenchmark(main, {
7+
n: [1e4],
8+
kind: ['lstat', 'stat']
9+
});
10+
11+
12+
function main(conf) {
13+
const n = conf.n >>> 0;
14+
15+
bench.start();
16+
(function r(cntr, fn) {
17+
if (cntr-- <= 0)
18+
return bench.end(n);
19+
fn(__filename, function() {
20+
r(cntr, fn);
21+
});
22+
}(n, fs[conf.kind]));
23+
}

benchmark/fs/bench-statSync.js

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
'use strict';
2+
3+
const common = require('../common');
4+
const fs = require('fs');
5+
6+
const bench = common.createBenchmark(main, {
7+
n: [1e4],
8+
kind: ['lstatSync', 'statSync']
9+
});
10+
11+
12+
function main(conf) {
13+
const n = conf.n >>> 0;
14+
const fn = fs[conf.kind];
15+
16+
bench.start();
17+
for (var i = 0; i < n; i++) {
18+
fn(__filename);
19+
}
20+
bench.end(n);
21+
}

0 commit comments

Comments
 (0)