Skip to content

Commit 17f869f

Browse files
committed
Change generateRandomFile to create all files with specified size
1 parent b26853f commit 17f869f

File tree

1 file changed

+10
-31
lines changed

1 file changed

+10
-31
lines changed

benchmark.ts

Lines changed: 10 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ const generateRandomFiles = (
7272
rootPath: string,
7373
numFiles: number,
7474
maxDepth: number,
75-
maxTotalSize: number,
75+
fileSize: number,
7676
) => {
7777
const metadata: { lastSync: number; files: { [key: string]: {} } } = {
7878
lastSync: 0,
@@ -108,9 +108,7 @@ const generateRandomFiles = (
108108
}
109109

110110
// Now generate files
111-
let totalSize = 0;
112-
// Calculate approximate size per file to ensure we create all files
113-
const targetSizePerFile = Math.floor(maxTotalSize / numFiles);
111+
const contentSize = fileSize / 2; // We divide by two as converting bytes to hex doubles the size
114112

115113
for (let i = 0; i < numFiles; i++) {
116114
// Pick a random folder to place the file in
@@ -121,28 +119,11 @@ const generateRandomFiles = (
121119
const fileName = crypto.randomBytes(8).toString("hex") + ".md";
122120
const filePath = path.join(targetFolder, fileName);
123121

124-
// Calculate remaining size and files
125-
const remainingSize = maxTotalSize - totalSize;
126-
const remainingFiles = numFiles - i;
127-
128-
if (remainingSize <= 0) {
129-
// If we've hit the max size but still need files, create empty files
130-
fs.writeFileSync(filePath, "");
131-
} else {
132-
// Calculate appropriate file size to ensure we can create all files
133-
const maxPossibleSize = Math.floor(remainingSize / remainingFiles);
134-
const contentSize =
135-
Math.floor(
136-
Math.random() * Math.min(maxPossibleSize, targetSizePerFile),
137-
) + 1;
138-
139-
// Generate random content
140-
const content = crypto.randomBytes(contentSize).toString("hex");
141-
142-
// Write file
143-
fs.writeFileSync(filePath, content);
144-
totalSize += contentSize;
145-
}
122+
// Generate random content
123+
const content = crypto.randomBytes(contentSize).toString("hex");
124+
125+
// Write file
126+
fs.writeFileSync(filePath, content);
146127

147128
const relativeFilePath = filePath.replace(`${rootPath}/`, "");
148129
metadata.files[relativeFilePath] = {
@@ -161,8 +142,6 @@ const generateRandomFiles = (
161142
);
162143
fs.mkdirSync(path.join(rootPath, ".obsidian"));
163144
fs.writeFileSync(metadataFilePath, JSON.stringify(metadata), { flag: "w" });
164-
165-
return totalSize;
166145
};
167146

168147
const cleanupRemote = async () => {
@@ -204,7 +183,7 @@ const BENCHMARK_DATA = [
204183
{
205184
files: 1,
206185
maxDepth: 1,
207-
maxSize: 7000,
186+
fileSize: 7 * 1024 * 1024,
208187
},
209188
];
210189

@@ -216,14 +195,14 @@ const BENCHMARK_DATA = [
216195
for (const data of BENCHMARK_DATA) {
217196
const vaultRootDir = path.join(
218197
benchmarkRootDir,
219-
`${data.files}-${data.maxDepth}-${data.maxSize}`,
198+
`${data.files}-${data.maxDepth}-${data.fileSize}`,
220199
);
221200
// Generates random files
222201
generateRandomFiles(
223202
vaultRootDir,
224203
data.files,
225204
data.maxDepth,
226-
data.maxSize,
205+
data.fileSize,
227206
);
228207

229208
// Run first sync by uploading all local files

0 commit comments

Comments
 (0)