Skip to content

Commit

Permalink
Rename batch -> chunk
Browse files Browse the repository at this point in the history
  • Loading branch information
mooori committed Mar 7, 2024
1 parent 6ed99c1 commit af25607
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
4 changes: 2 additions & 2 deletions tests/zkasm/helpers/InstructionTracer.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ class InstructionTracer {
// https://nodejs.org/api/fs.html#using-fswritefile-with-file-descriptors
throw new Error("provide a file name (not descriptor) to write to");
}
// Writing in batches of 1000 instructions to limit memory usage,
// Writing in chunks of 1000 instructions to limit memory usage,
// as raw traces might grow big.
dataDump.writeToFileInBatches(this.rawTrace, path, 1000);
dataDump.writeToFileInChunks(this.rawTrace, path, 1000);
}
}

Expand Down
16 changes: 8 additions & 8 deletions tests/zkasm/helpers/data-dump.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
const fs = require('fs');

/**
* Writes `lines` to a file in batches to limit memory usage.
* Writes `lines` to a file in chunks to limit memory usage.
*
* @param {string[]} lines - each string in the array is written on its own line
* @param {string} filePath
* @param {number} batchSize
* @param {number} chunkSize
*/
function writeToFileInBatches(lines, filePath, batchSize) {
function writeToFileInChunks(lines, filePath, chunkSize) {
// If the file already exists, clear it by writing empty string.
if (fs.existsSync(filePath)) {
fs.writeFileSync(filePath, "", "utf-8");
}

// Append batches to the file (will be created if it doesn't exist).
for (let i = 0; i < lines.length; i += batchSize) {
let batchedLines = lines.slice(i, i + batchSize).join("\n") + "\n";
fs.appendFileSync(filePath, batchedLines, "utf-8");
// Append chunks to the file (will be created if it doesn't exist).
for (let i = 0; i < lines.length; i += chunkSize) {
let linesToWrite = lines.slice(i, i + chunkSize).join("\n") + "\n";
fs.appendFileSync(filePath, linesToWrite, "utf-8");
}
}

module.exports = {
writeToFileInBatches
writeToFileInChunks
}

0 comments on commit af25607

Please sign in to comment.