Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fs: include more fs.stat*() optimizations #11665

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 16 additions & 6 deletions benchmark/fs/bench-stat.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,30 @@ const common = require('../common');
const fs = require('fs');

const bench = common.createBenchmark(main, {
n: [1e4],
kind: ['lstat', 'stat']
n: [20e4],
kind: ['fstat', 'lstat', 'stat']
});


function main(conf) {
const n = conf.n >>> 0;
const kind = conf.kind;
var arg;
if (kind === 'fstat')
arg = fs.openSync(__filename, 'r');
else
arg = __filename;

bench.start();
(function r(cntr, fn) {
if (cntr-- <= 0)
return bench.end(n);
fn(__filename, function() {
if (cntr-- <= 0) {
bench.end(n);
if (kind === 'fstat')
fs.closeSync(arg);
return;
}
fn(arg, function() {
r(cntr, fn);
});
}(n, fs[conf.kind]));
}(n, fs[kind]));
}
37 changes: 12 additions & 25 deletions benchmark/fs/bench-statSync.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,36 +4,23 @@ const common = require('../common');
const fs = require('fs');

const bench = common.createBenchmark(main, {
n: [1e4],
n: [1e6],
kind: ['fstatSync', 'lstatSync', 'statSync']
});


function main(conf) {
const n = conf.n >>> 0;
var fn;
var i;
switch (conf.kind) {
case 'statSync':
case 'lstatSync':
fn = fs[conf.kind];
bench.start();
for (i = 0; i < n; i++) {
fn(__filename);
}
bench.end(n);
break;
case 'fstatSync':
fn = fs.fstatSync;
const fd = fs.openSync(__filename, 'r');
bench.start();
for (i = 0; i < n; i++) {
fn(fd);
}
bench.end(n);
fs.closeSync(fd);
break;
default:
throw new Error('Invalid kind argument');
const kind = conf.kind;
const arg = (kind === 'fstatSync' ? fs.openSync(__filename, 'r') : __dirname);
const fn = fs[conf.kind];

bench.start();
for (var i = 0; i < n; i++) {
fn(arg);
}
bench.end(n);

if (kind === 'fstat')
fs.closeSync(arg);
}
17 changes: 17 additions & 0 deletions benchmark/fs/readFileSync.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
'use strict';

var common = require('../common.js');
var fs = require('fs');

var bench = common.createBenchmark(main, {
n: [60e4]
});

function main(conf) {
var n = +conf.n;

bench.start();
for (var i = 0; i < n; ++i)
fs.readFileSync(__filename);
bench.end(n);
}
Loading