From fa1b3da40ec5793a1d6bd2428da2d55dc674cd5a Mon Sep 17 00:00:00 2001 From: Yagiz Nizipli Date: Sun, 21 Aug 2022 10:28:04 -0400 Subject: [PATCH] fs: add encoding parameter to benchmarks PR-URL: https://github.com/nodejs/node/pull/44278 Reviewed-By: Matteo Collina Reviewed-By: Rafael Gonzaga --- benchmark/fs/readfile-partitioned.js | 9 +++++---- benchmark/fs/readfile-promises.js | 5 +++-- benchmark/fs/readfile.js | 5 +++-- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/benchmark/fs/readfile-partitioned.js b/benchmark/fs/readfile-partitioned.js index fac331ec38b..e0ca7a2c1bb 100644 --- a/benchmark/fs/readfile-partitioned.js +++ b/benchmark/fs/readfile-partitioned.js @@ -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 { @@ -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) { diff --git a/benchmark/fs/readfile-promises.js b/benchmark/fs/readfile-promises.js index 5cfa5b4cc02..0fa92fdffad 100644 --- a/benchmark/fs/readfile-promises.js +++ b/benchmark/fs/readfile-promises.js @@ -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 { @@ -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)); } diff --git a/benchmark/fs/readfile.js b/benchmark/fs/readfile.js index e27fe08f43c..575ceff34eb 100644 --- a/benchmark/fs/readfile.js +++ b/benchmark/fs/readfile.js @@ -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 { @@ -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) {