Permalink
Browse files

fs: include more fs.stat*() optimizations

Including:

* Move async *stat() functions to FillStatsArray() now used by the
sync *stat() functions

* Avoid creating fs.Stats instances for implicit async/sync *stat()
calls used in various fs functions

* Store reference to Float64Array data on C++ side for easier/faster
access, instead of passing from JS to C++ on every async/sync *stat()
call

PR-URL: #11665
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
  • Loading branch information...
mscdex authored and jasnell committed Mar 12, 2017
1 parent 3d7245c commit 6a5ab5d550719f416683ec0d588461b8bc9a8787
View
@@ -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]));
}
@@ -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);
}
@@ -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);
}
Oops, something went wrong.

0 comments on commit 6a5ab5d

Please sign in to comment.