From 6614a47a9827b69d80f4d72ae40538d998ebc748 Mon Sep 17 00:00:00 2001 From: Huakun Shen Date: Sun, 23 Mar 2025 08:16:47 -0400 Subject: [PATCH] Reduce default file size in sequential write test, implement streaming read in sequential read test, set default target directory in store, and add VSCode settings for Deno support. --- .vscode/settings.json | 3 +++ dev.ts | 2 +- speedtest/lib.ts | 10 ++++++---- src/lib/store.ts | 2 +- 4 files changed, 11 insertions(+), 6 deletions(-) create mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..b943dbc --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "deno.enable": true +} \ No newline at end of file diff --git a/dev.ts b/dev.ts index 8885505..61d40ba 100644 --- a/dev.ts +++ b/dev.ts @@ -6,7 +6,7 @@ const testPath = "./test.txt"; const writeResult = await sequentialWriteTest( { filePath: testPath, - sizeInMB: 1000, + sizeInMB: 200, rounds: 10, bufferSizeMB: 1, keepTheFile: true, diff --git a/speedtest/lib.ts b/speedtest/lib.ts index 803b1c4..78182e6 100644 --- a/speedtest/lib.ts +++ b/speedtest/lib.ts @@ -65,14 +65,16 @@ export async function sequentialReadTest( ): Promise { const { filePath, rounds, deleteAfter } = options; const file = await Deno.open(filePath, { read: true }); - const buffer = new Uint8Array(oneMB); // 1MB buffer + const reader = file.readable.getReader(); const start = performance.now(); let totalMB = 0; - while ((await file.read(buffer)) !== null) { - totalMB += 1; + + let readResult; + while (!(readResult = await reader.read()).done) { + totalMB += readResult.value.length / oneMB; } const totalDuration = (performance.now() - start) / 1000; - file.close(); + // file.close(); if (options.deleteAfter) { Deno.removeSync(filePath); } diff --git a/src/lib/store.ts b/src/lib/store.ts index 0c0acf9..31ef91f 100644 --- a/src/lib/store.ts +++ b/src/lib/store.ts @@ -1,4 +1,4 @@ import { writable } from "svelte/store"; export const stress = writable(1); -export const targetDir = writable(undefined); +export const targetDir = writable("/Users/kunkun/Desktop");