Skip to content

Commit

Permalink
fixup! fs: add c++ fast path for writeFileSync utf8
Browse files Browse the repository at this point in the history
  • Loading branch information
CanadaHonk committed Sep 26, 2023
1 parent 12c0d7f commit 7ab6586
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions benchmark/fs/bench-writeFileSync.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ tmpdir.refresh();
const bench = common.createBenchmark(main, {
encoding: ['utf8'],
hasFileDescriptor: ['true', 'false'],
stringLength: [1024, 4096, 65535],
// stringLength: [1024, 4096, 65535, 1024 * 1024],
stringLength: [1024, 4096, 65535, 1024 * 1024],
func: [ 'writeFile', 'appendFile' ],
n: [1e3],
});

function main({ n, encoding, stringLength, hasFileDescriptor }) {
function main({ n, func, encoding, stringLength, hasFileDescriptor }) {
tmpdir.refresh();
const enc = encoding === 'undefined' ? undefined : encoding;
const path = tmpdir.resolve(`.writefilesync-file-${Date.now()}`);
Expand All @@ -23,9 +23,11 @@ function main({ n, encoding, stringLength, hasFileDescriptor }) {

const data = 'a'.repeat(stringLength);

const fn = fs[func + 'Sync'];

bench.start();
for (let i = 0; i < n; ++i) {
fs.writeFileSync(file, data, enc);
fn(file, data, enc);
}
bench.end(n);

Expand Down

0 comments on commit 7ab6586

Please sign in to comment.