test: added fs benchmark test
Modified fs benchmarks to use more unique args to avoid collision. PR-URL: https://github.com/nodejs/node/pull/16049 Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Evan Lucas <evanlucas@me.com> Reviewed-By: Stephen Belanger <admin@stephenbelanger.com>
This commit is contained in:
parent
7525df7af2
commit
58d26e2421
@ -8,21 +8,21 @@ const relative_path = path.relative(__dirname, '../../lib/');
|
|||||||
|
|
||||||
const bench = common.createBenchmark(main, {
|
const bench = common.createBenchmark(main, {
|
||||||
n: [1e4],
|
n: [1e4],
|
||||||
type: ['relative', 'resolved'],
|
pathType: ['relative', 'resolved'],
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
function main(conf) {
|
function main(conf) {
|
||||||
const n = conf.n >>> 0;
|
const n = conf.n >>> 0;
|
||||||
const type = conf.type;
|
const pathType = conf.pathType;
|
||||||
|
|
||||||
bench.start();
|
bench.start();
|
||||||
if (type === 'relative')
|
if (pathType === 'relative')
|
||||||
relativePath(n);
|
relativePath(n);
|
||||||
else if (type === 'resolved')
|
else if (pathType === 'resolved')
|
||||||
resolvedPath(n);
|
resolvedPath(n);
|
||||||
else
|
else
|
||||||
throw new Error(`unknown "type": ${type}`);
|
throw new Error(`unknown "pathType": ${pathType}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
function relativePath(n) {
|
function relativePath(n) {
|
||||||
|
@ -10,21 +10,21 @@ const relative_path = path.relative(__dirname, '../../lib/');
|
|||||||
|
|
||||||
const bench = common.createBenchmark(main, {
|
const bench = common.createBenchmark(main, {
|
||||||
n: [1e4],
|
n: [1e4],
|
||||||
type: ['relative', 'resolved'],
|
pathType: ['relative', 'resolved'],
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
function main(conf) {
|
function main(conf) {
|
||||||
const n = conf.n >>> 0;
|
const n = conf.n >>> 0;
|
||||||
const type = conf.type;
|
const pathType = conf.pathType;
|
||||||
|
|
||||||
bench.start();
|
bench.start();
|
||||||
if (type === 'relative')
|
if (pathType === 'relative')
|
||||||
relativePath(n);
|
relativePath(n);
|
||||||
else if (type === 'resolved')
|
else if (pathType === 'resolved')
|
||||||
resolvedPath(n);
|
resolvedPath(n);
|
||||||
else
|
else
|
||||||
throw new Error(`unknown "type": ${type}`);
|
throw new Error(`unknown "pathType": ${pathType}`);
|
||||||
bench.end(n);
|
bench.end(n);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,15 +5,15 @@ const fs = require('fs');
|
|||||||
|
|
||||||
const bench = common.createBenchmark(main, {
|
const bench = common.createBenchmark(main, {
|
||||||
n: [20e4],
|
n: [20e4],
|
||||||
kind: ['fstat', 'lstat', 'stat']
|
statType: ['fstat', 'lstat', 'stat']
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
function main(conf) {
|
function main(conf) {
|
||||||
const n = conf.n >>> 0;
|
const n = conf.n >>> 0;
|
||||||
const kind = conf.kind;
|
const statType = conf.statType;
|
||||||
var arg;
|
var arg;
|
||||||
if (kind === 'fstat')
|
if (statType === 'fstat')
|
||||||
arg = fs.openSync(__filename, 'r');
|
arg = fs.openSync(__filename, 'r');
|
||||||
else
|
else
|
||||||
arg = __filename;
|
arg = __filename;
|
||||||
@ -22,12 +22,12 @@ function main(conf) {
|
|||||||
(function r(cntr, fn) {
|
(function r(cntr, fn) {
|
||||||
if (cntr-- <= 0) {
|
if (cntr-- <= 0) {
|
||||||
bench.end(n);
|
bench.end(n);
|
||||||
if (kind === 'fstat')
|
if (statType === 'fstat')
|
||||||
fs.closeSync(arg);
|
fs.closeSync(arg);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
fn(arg, function() {
|
fn(arg, function() {
|
||||||
r(cntr, fn);
|
r(cntr, fn);
|
||||||
});
|
});
|
||||||
}(n, fs[kind]));
|
}(n, fs[statType]));
|
||||||
}
|
}
|
||||||
|
@ -5,15 +5,17 @@ const fs = require('fs');
|
|||||||
|
|
||||||
const bench = common.createBenchmark(main, {
|
const bench = common.createBenchmark(main, {
|
||||||
n: [1e6],
|
n: [1e6],
|
||||||
kind: ['fstatSync', 'lstatSync', 'statSync']
|
statSyncType: ['fstatSync', 'lstatSync', 'statSync']
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
function main(conf) {
|
function main(conf) {
|
||||||
const n = conf.n >>> 0;
|
const n = conf.n >>> 0;
|
||||||
const kind = conf.kind;
|
const statSyncType = conf.statSyncType;
|
||||||
const arg = (kind === 'fstatSync' ? fs.openSync(__filename, 'r') : __dirname);
|
const arg = (statSyncType === 'fstatSync' ?
|
||||||
const fn = fs[conf.kind];
|
fs.openSync(__filename, 'r') :
|
||||||
|
__dirname);
|
||||||
|
const fn = fs[statSyncType];
|
||||||
|
|
||||||
bench.start();
|
bench.start();
|
||||||
for (var i = 0; i < n; i++) {
|
for (var i = 0; i < n; i++) {
|
||||||
@ -21,6 +23,6 @@ function main(conf) {
|
|||||||
}
|
}
|
||||||
bench.end(n);
|
bench.end(n);
|
||||||
|
|
||||||
if (kind === 'fstat')
|
if (statSyncType === 'fstat')
|
||||||
fs.closeSync(arg);
|
fs.closeSync(arg);
|
||||||
}
|
}
|
||||||
|
@ -5,21 +5,22 @@ const path = require('path');
|
|||||||
const common = require('../common.js');
|
const common = require('../common.js');
|
||||||
const filename = path.resolve(__dirname, '.removeme-benchmark-garbage');
|
const filename = path.resolve(__dirname, '.removeme-benchmark-garbage');
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const filesize = 1000 * 1024 * 1024;
|
|
||||||
const assert = require('assert');
|
const assert = require('assert');
|
||||||
|
|
||||||
var type, encoding, size;
|
let encodingType, encoding, size, filesize;
|
||||||
|
|
||||||
const bench = common.createBenchmark(main, {
|
const bench = common.createBenchmark(main, {
|
||||||
type: ['buf', 'asc', 'utf'],
|
encodingType: ['buf', 'asc', 'utf'],
|
||||||
|
filesize: [1000 * 1024 * 1024],
|
||||||
size: [1024, 4096, 65535, 1024 * 1024]
|
size: [1024, 4096, 65535, 1024 * 1024]
|
||||||
});
|
});
|
||||||
|
|
||||||
function main(conf) {
|
function main(conf) {
|
||||||
type = conf.type;
|
encodingType = conf.encodingType;
|
||||||
size = +conf.size;
|
size = +conf.size;
|
||||||
|
filesize = conf.filesize;
|
||||||
|
|
||||||
switch (type) {
|
switch (encodingType) {
|
||||||
case 'buf':
|
case 'buf':
|
||||||
encoding = null;
|
encoding = null;
|
||||||
break;
|
break;
|
||||||
@ -30,7 +31,7 @@ function main(conf) {
|
|||||||
encoding = 'utf8';
|
encoding = 'utf8';
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw new Error('invalid type');
|
throw new Error(`invalid encodingType: ${encodingType}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
makeFile(runTest);
|
makeFile(runTest);
|
||||||
|
@ -8,18 +8,18 @@ const fs = require('fs');
|
|||||||
|
|
||||||
const bench = common.createBenchmark(main, {
|
const bench = common.createBenchmark(main, {
|
||||||
dur: [5],
|
dur: [5],
|
||||||
type: ['buf', 'asc', 'utf'],
|
encodingType: ['buf', 'asc', 'utf'],
|
||||||
size: [2, 1024, 65535, 1024 * 1024]
|
size: [2, 1024, 65535, 1024 * 1024]
|
||||||
});
|
});
|
||||||
|
|
||||||
function main(conf) {
|
function main(conf) {
|
||||||
const dur = +conf.dur;
|
const dur = +conf.dur;
|
||||||
const type = conf.type;
|
const encodingType = conf.encodingType;
|
||||||
const size = +conf.size;
|
const size = +conf.size;
|
||||||
var encoding;
|
var encoding;
|
||||||
|
|
||||||
var chunk;
|
var chunk;
|
||||||
switch (type) {
|
switch (encodingType) {
|
||||||
case 'buf':
|
case 'buf':
|
||||||
chunk = Buffer.alloc(size, 'b');
|
chunk = Buffer.alloc(size, 'b');
|
||||||
break;
|
break;
|
||||||
@ -32,7 +32,7 @@ function main(conf) {
|
|||||||
encoding = 'utf8';
|
encoding = 'utf8';
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw new Error('invalid type');
|
throw new Error(`invalid encodingType: ${encodingType}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
try { fs.unlinkSync(filename); } catch (e) {}
|
try { fs.unlinkSync(filename); } catch (e) {}
|
||||||
|
17
test/parallel/test-benchmark-fs.js
Normal file
17
test/parallel/test-benchmark-fs.js
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
require('../common');
|
||||||
|
const runBenchmark = require('../common/benchmark');
|
||||||
|
|
||||||
|
runBenchmark('fs', [
|
||||||
|
'n=1',
|
||||||
|
'size=1',
|
||||||
|
'dur=1',
|
||||||
|
'len=1024',
|
||||||
|
'concurrent=1',
|
||||||
|
'pathType=relative',
|
||||||
|
'statType=fstat',
|
||||||
|
'statSyncType=fstatSync',
|
||||||
|
'encodingType=buf',
|
||||||
|
'filesize=1024'
|
||||||
|
]);
|
Loading…
x
Reference in New Issue
Block a user