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
45 changes: 45 additions & 0 deletions benchmark.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
const fs = require('fs').promises;

async function runBenchmark() {
console.log("Starting I/O benchmark with fs.access...");

const dummyFilePath = 'dummy_logs_2.json';
await fs.writeFile(dummyFilePath, "x".repeat(1024 * 1024 * 5)); // 5MB dummy file

// 1. With fs.access
const start1 = process.hrtime.bigint();
const tasks1 = [];
for (let i = 0; i < 50; i++) {
tasks1.push((async () => {
try {
await fs.access(dummyFilePath);
await fs.readFile(dummyFilePath, 'utf8');
} catch (e) { }
})());
}
await Promise.all(tasks1);
const end1 = process.hrtime.bigint();
console.log(`Time taken with fs.access (file exists): ${Number(end1 - start1) / 1000000} ms`);

// 2. File missing - With fs.access
const missingFilePath = 'does_not_exist.json';
const start3 = process.hrtime.bigint();
const tasks3 = [];
for (let i = 0; i < 1000; i++) {
tasks3.push((async () => {
try {
await fs.access(missingFilePath);
await fs.readFile(missingFilePath, 'utf8');
} catch (e) { }
})());
}
await Promise.all(tasks3);
const end3 = process.hrtime.bigint();
console.log(`Time taken with fs.access (file missing): ${Number(end3 - start3) / 1000000} ms`);

// Clean up
await fs.unlink(dummyFilePath).catch(() => {});
process.exit(0);
}

runBenchmark().catch(console.error);
8 changes: 6 additions & 2 deletions electron/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,9 @@ ipcMain.on('save-log', (event, data, customPath) => {
console.error("Corrupted logs recovered:", e);
try {
await fs.copyFile(filePath, `${filePath}.corrupt.bak`);
} catch (err) { }
} catch (backupErr) {
console.error("Failed to backup corrupted logs:", backupErr);
}
}
logs = {};
}
Expand Down Expand Up @@ -298,7 +300,9 @@ ipcMain.on('open-logs-folder', async (event, customPath) => {
try {
await fs.access(dirPath);
shell.openPath(dirPath);
} catch (e) { }
} catch (e) {
// Directory does not exist or cannot be accessed
}
});

ipcMain.on('set-enforcement', (event, config) => {
Expand Down