Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
fs: add encoding parameter to benchmarks
  • Loading branch information
anonrig committed Aug 19, 2022
commit e48b16e153778becead64acdea5e35894f8a3262
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