Skip to content

Commit

Permalink
fs: add encoding parameter to benchmarks
Browse files Browse the repository at this point in the history
PR-URL: #44278
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
  • Loading branch information
anonrig authored and juanarbol committed Oct 11, 2022
1 parent 0bf57df commit bf217f8
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
9 changes: 5 additions & 4 deletions benchmark/fs/readfile-partitioned.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@ const zlib = require('zlib');
const assert = require('assert');

const bench = common.createBenchmark(main, {
dur: [5],
duration: [5],
encoding: ['', 'utf-8'],
len: [1024, 16 * 1024 * 1024],
concurrent: [1, 10]
});

function main({ len, dur, concurrent }) {
function main({ len, duration, concurrent, encoding }) {
try {
fs.unlinkSync(filename);
} catch {
Expand All @@ -47,10 +48,10 @@ function main({ len, dur, concurrent }) {
} catch {
// Continue regardless of error.
}
}, dur * 1000);
}, duration * 1000);

function read() {
fs.readFile(filename, afterRead);
fs.readFile(filename, encoding, afterRead);
}

function afterRead(er, data) {
Expand Down
5 changes: 3 additions & 2 deletions benchmark/fs/readfile-promises.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@ const filename = path.resolve(tmpdir.path,

const bench = common.createBenchmark(main, {
duration: [5],
encoding: ['', 'utf-8'],
len: [1024, 16 * 1024 * 1024],
concurrent: [1, 10]
});

function main({ len, duration, concurrent }) {
function main({ len, duration, concurrent, encoding }) {
try {
fs.unlinkSync(filename);
} catch {
Expand All @@ -44,7 +45,7 @@ function main({ len, duration, concurrent }) {
}, duration * 1000);

function read() {
fs.promises.readFile(filename)
fs.promises.readFile(filename, encoding)
.then((res) => afterRead(undefined, res))
.catch((err) => afterRead(err));
}
Expand Down
5 changes: 3 additions & 2 deletions benchmark/fs/readfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@ const filename = path.resolve(tmpdir.path,

const bench = common.createBenchmark(main, {
duration: [5],
encoding: ['', 'utf-8'],
len: [1024, 16 * 1024 * 1024],
concurrent: [1, 10]
});

function main({ len, duration, concurrent }) {
function main({ len, duration, concurrent, encoding }) {
try {
fs.unlinkSync(filename);
} catch {
Expand All @@ -44,7 +45,7 @@ function main({ len, duration, concurrent }) {
}, duration * 1000);

function read() {
fs.readFile(filename, afterRead);
fs.readFile(filename, encoding, afterRead);
}

function afterRead(er, data) {
Expand Down

0 comments on commit bf217f8

Please sign in to comment.