Skip to content

Commit a79b982

Browse files
ctdiotargos
authored andcommitted
test: added fs benchmark test
Modified fs benchmarks to use more unique args to avoid collision. PR-URL: #16049 Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Evan Lucas <evanlucas@me.com> Reviewed-By: Stephen Belanger <admin@stephenbelanger.com>
1 parent 92b5cf1 commit a79b982

File tree

7 files changed

+50
-30
lines changed

7 files changed

+50
-30
lines changed

benchmark/fs/bench-realpath.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,21 @@ const relative_path = path.relative(__dirname, '../../lib/');
88

99
const bench = common.createBenchmark(main, {
1010
n: [1e4],
11-
type: ['relative', 'resolved'],
11+
pathType: ['relative', 'resolved'],
1212
});
1313

1414

1515
function main(conf) {
1616
const n = conf.n >>> 0;
17-
const type = conf.type;
17+
const pathType = conf.pathType;
1818

1919
bench.start();
20-
if (type === 'relative')
20+
if (pathType === 'relative')
2121
relativePath(n);
22-
else if (type === 'resolved')
22+
else if (pathType === 'resolved')
2323
resolvedPath(n);
2424
else
25-
throw new Error(`unknown "type": ${type}`);
25+
throw new Error(`unknown "pathType": ${pathType}`);
2626
}
2727

2828
function relativePath(n) {

benchmark/fs/bench-realpathSync.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,21 @@ const relative_path = path.relative(__dirname, '../../lib/');
1010

1111
const bench = common.createBenchmark(main, {
1212
n: [1e4],
13-
type: ['relative', 'resolved'],
13+
pathType: ['relative', 'resolved'],
1414
});
1515

1616

1717
function main(conf) {
1818
const n = conf.n >>> 0;
19-
const type = conf.type;
19+
const pathType = conf.pathType;
2020

2121
bench.start();
22-
if (type === 'relative')
22+
if (pathType === 'relative')
2323
relativePath(n);
24-
else if (type === 'resolved')
24+
else if (pathType === 'resolved')
2525
resolvedPath(n);
2626
else
27-
throw new Error(`unknown "type": ${type}`);
27+
throw new Error(`unknown "pathType": ${pathType}`);
2828
bench.end(n);
2929
}
3030

benchmark/fs/bench-stat.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@ const fs = require('fs');
55

66
const bench = common.createBenchmark(main, {
77
n: [20e4],
8-
kind: ['fstat', 'lstat', 'stat']
8+
statType: ['fstat', 'lstat', 'stat']
99
});
1010

1111

1212
function main(conf) {
1313
const n = conf.n >>> 0;
14-
const kind = conf.kind;
14+
const statType = conf.statType;
1515
var arg;
16-
if (kind === 'fstat')
16+
if (statType === 'fstat')
1717
arg = fs.openSync(__filename, 'r');
1818
else
1919
arg = __filename;
@@ -22,12 +22,12 @@ function main(conf) {
2222
(function r(cntr, fn) {
2323
if (cntr-- <= 0) {
2424
bench.end(n);
25-
if (kind === 'fstat')
25+
if (statType === 'fstat')
2626
fs.closeSync(arg);
2727
return;
2828
}
2929
fn(arg, function() {
3030
r(cntr, fn);
3131
});
32-
}(n, fs[kind]));
32+
}(n, fs[statType]));
3333
}

benchmark/fs/bench-statSync.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,24 @@ const fs = require('fs');
55

66
const bench = common.createBenchmark(main, {
77
n: [1e6],
8-
kind: ['fstatSync', 'lstatSync', 'statSync']
8+
statSyncType: ['fstatSync', 'lstatSync', 'statSync']
99
});
1010

1111

1212
function main(conf) {
1313
const n = conf.n >>> 0;
14-
const kind = conf.kind;
15-
const arg = (kind === 'fstatSync' ? fs.openSync(__filename, 'r') : __dirname);
16-
const fn = fs[conf.kind];
14+
const statSyncType = conf.statSyncType;
15+
const arg = (statSyncType === 'fstatSync' ?
16+
fs.openSync(__filename, 'r') :
17+
__dirname);
18+
const fn = fs[statSyncType];
1719

1820
bench.start();
1921
for (var i = 0; i < n; i++) {
2022
fn(arg);
2123
}
2224
bench.end(n);
2325

24-
if (kind === 'fstat')
26+
if (statSyncType === 'fstat')
2527
fs.closeSync(arg);
2628
}

benchmark/fs/read-stream-throughput.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,22 @@ const path = require('path');
55
const common = require('../common.js');
66
const filename = path.resolve(__dirname, '.removeme-benchmark-garbage');
77
const fs = require('fs');
8-
const filesize = 1000 * 1024 * 1024;
98
const assert = require('assert');
109

11-
var type, encoding, size;
10+
let encodingType, encoding, size, filesize;
1211

1312
const bench = common.createBenchmark(main, {
14-
type: ['buf', 'asc', 'utf'],
13+
encodingType: ['buf', 'asc', 'utf'],
14+
filesize: [1000 * 1024 * 1024],
1515
size: [1024, 4096, 65535, 1024 * 1024]
1616
});
1717

1818
function main(conf) {
19-
type = conf.type;
19+
encodingType = conf.encodingType;
2020
size = +conf.size;
21+
filesize = conf.filesize;
2122

22-
switch (type) {
23+
switch (encodingType) {
2324
case 'buf':
2425
encoding = null;
2526
break;
@@ -30,7 +31,7 @@ function main(conf) {
3031
encoding = 'utf8';
3132
break;
3233
default:
33-
throw new Error('invalid type');
34+
throw new Error(`invalid encodingType: ${encodingType}`);
3435
}
3536

3637
makeFile(runTest);

benchmark/fs/write-stream-throughput.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,18 @@ const fs = require('fs');
88

99
const bench = common.createBenchmark(main, {
1010
dur: [5],
11-
type: ['buf', 'asc', 'utf'],
11+
encodingType: ['buf', 'asc', 'utf'],
1212
size: [2, 1024, 65535, 1024 * 1024]
1313
});
1414

1515
function main(conf) {
1616
const dur = +conf.dur;
17-
const type = conf.type;
17+
const encodingType = conf.encodingType;
1818
const size = +conf.size;
1919
var encoding;
2020

2121
var chunk;
22-
switch (type) {
22+
switch (encodingType) {
2323
case 'buf':
2424
chunk = Buffer.alloc(size, 'b');
2525
break;
@@ -32,7 +32,7 @@ function main(conf) {
3232
encoding = 'utf8';
3333
break;
3434
default:
35-
throw new Error('invalid type');
35+
throw new Error(`invalid encodingType: ${encodingType}`);
3636
}
3737

3838
try { fs.unlinkSync(filename); } catch (e) {}

test/parallel/test-benchmark-fs.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
'use strict';
2+
3+
require('../common');
4+
const runBenchmark = require('../common/benchmark');
5+
6+
runBenchmark('fs', [
7+
'n=1',
8+
'size=1',
9+
'dur=1',
10+
'len=1024',
11+
'concurrent=1',
12+
'pathType=relative',
13+
'statType=fstat',
14+
'statSyncType=fstatSync',
15+
'encodingType=buf',
16+
'filesize=1024'
17+
]);

0 commit comments

Comments
 (0)