Skip to content

Commit 4dcfe8c

Browse files
committed
fs: add encoding parameter to benchmarks
1 parent a957f7b commit 4dcfe8c

File tree

3 files changed

+19
-8
lines changed

3 files changed

+19
-8
lines changed

benchmark/fs/readfile-partitioned.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,13 @@ const zlib = require('zlib');
1717
const assert = require('assert');
1818

1919
const bench = common.createBenchmark(main, {
20-
dur: [5],
20+
duration: [5],
21+
encoding: ['undefined', 'utf-8'],
2122
len: [1024, 16 * 1024 * 1024],
2223
concurrent: [1, 10]
2324
});
2425

25-
function main({ len, dur, concurrent }) {
26+
function main({ len, duration, concurrent, encoding }) {
2627
try {
2728
fs.unlinkSync(filename);
2829
} catch {
@@ -47,10 +48,14 @@ function main({ len, dur, concurrent }) {
4748
} catch {
4849
// Continue regardless of error.
4950
}
50-
}, dur * 1000);
51+
}, duration * 1000);
5152

5253
function read() {
53-
fs.readFile(filename, afterRead);
54+
if (encoding !== 'undefined') {
55+
fs.readFile(filename, encoding, afterRead);
56+
} else {
57+
fs.readFile(filename, afterRead);
58+
}
5459
}
5560

5661
function afterRead(er, data) {

benchmark/fs/readfile-promises.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,12 @@ const filename = path.resolve(tmpdir.path,
1515

1616
const bench = common.createBenchmark(main, {
1717
duration: [5],
18+
encoding: ['undefined', 'utf-8'],
1819
len: [1024, 16 * 1024 * 1024],
1920
concurrent: [1, 10]
2021
});
2122

22-
function main({ len, duration, concurrent }) {
23+
function main({ len, duration, concurrent, encoding }) {
2324
try {
2425
fs.unlinkSync(filename);
2526
} catch {
@@ -44,7 +45,7 @@ function main({ len, duration, concurrent }) {
4445
}, duration * 1000);
4546

4647
function read() {
47-
fs.promises.readFile(filename)
48+
fs.promises.readFile(filename, encoding === 'undefined' ? undefined : encoding)
4849
.then((res) => afterRead(undefined, res))
4950
.catch((err) => afterRead(err));
5051
}

benchmark/fs/readfile.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,12 @@ const filename = path.resolve(tmpdir.path,
1515

1616
const bench = common.createBenchmark(main, {
1717
duration: [5],
18+
encoding: ['undefined', 'utf-8'],
1819
len: [1024, 16 * 1024 * 1024],
1920
concurrent: [1, 10]
2021
});
2122

22-
function main({ len, duration, concurrent }) {
23+
function main({ len, duration, concurrent, encoding }) {
2324
try {
2425
fs.unlinkSync(filename);
2526
} catch {
@@ -44,7 +45,11 @@ function main({ len, duration, concurrent }) {
4445
}, duration * 1000);
4546

4647
function read() {
47-
fs.readFile(filename, afterRead);
48+
if (encoding !== 'undefined') {
49+
fs.readFile(filename, encoding, afterRead);
50+
} else {
51+
fs.readFile(filename, afterRead);
52+
}
4853
}
4954

5055
function afterRead(er, data) {

0 commit comments

Comments
 (0)