feat: add zip speed test

This commit is contained in:
DecDuck
2025-08-15 12:17:10 +10:00
parent 7ec5e9f215
commit 913dc2f58d
4 changed files with 47 additions and 30 deletions

View File

@ -1,6 +1,7 @@
import test from "ava"; import test from "ava";
import fs from "node:fs"; import fs from "node:fs";
import path from "path"; import path from "path";
import prettyBytes from "pretty-bytes";
import droplet, { DropletHandler, generateManifest } from "../index.js"; import droplet, { DropletHandler, generateManifest } from "../index.js";
@ -78,7 +79,12 @@ test("read file offset", async (t) => {
fs.writeFileSync(dirName + "/TESTFILE", testString); fs.writeFileSync(dirName + "/TESTFILE", testString);
const dropletHandler = new DropletHandler(); const dropletHandler = new DropletHandler();
const stream = dropletHandler.readFile(dirName, "TESTFILE", BigInt(1), BigInt(4)); const stream = dropletHandler.readFile(
dirName,
"TESTFILE",
BigInt(1),
BigInt(4)
);
let finalString = ""; let finalString = "";
@ -96,37 +102,40 @@ test("read file offset", async (t) => {
fs.rmSync(dirName, { recursive: true }); fs.rmSync(dirName, { recursive: true });
}); });
test("zip file reader", async (t) => { test("zip speed test", async (t) => {
return t.pass(); t.timeout(100_000_000);
t.timeout(10_000);
const dropletHandler = new DropletHandler(); const dropletHandler = new DropletHandler();
const manifest = JSON.parse(
await new Promise((r, e) =>
generateManifest(
dropletHandler,
"./assets/TheGame.zip",
(_, __) => {},
(_, __) => {},
(err, manifest) => (err ? e(err) : r(manifest))
)
)
);
const stream = dropletHandler.readFile( const stream = dropletHandler.readFile("./assets/TheGame.zip", "setup.exe");
"./assets/TheGame.zip",
"setup.exe",
BigInt(10),
BigInt(20)
);
let totalRead = 0;
let totalSeconds = 0;
let finalString = ""; let lastTime = process.hrtime.bigint();
const timeThreshold = BigInt(1_000_000_000);
let runningTotal = 0;
let runningTime = BigInt(0);
for await (const chunk of stream.getStream()) { for await (const chunk of stream.getStream()) {
// Do something with each 'chunk' // Do something with each 'chunk'
finalString = String.fromCharCode.apply(null, chunk); const currentTime = process.hrtime.bigint();
if(finalString.length > 100) break; const timeDiff = currentTime - lastTime;
lastTime = currentTime;
runningTime += timeDiff;
runningTotal += chunk.length;
if (runningTime >= timeThreshold) {
console.log(`${prettyBytes(runningTotal)}/s`);
totalRead += runningTotal;
totalSeconds += 1;
runningTime = BigInt(0);
runningTotal = 0;
}
} }
const roughAverage = totalRead / totalSeconds;
console.log(`total rough average: ${prettyBytes(roughAverage)}/s`)
t.pass(); t.pass();
}); });

View File

@ -1,3 +1,4 @@
yes "droplet is awesome" | dd of=./setup.exe bs=1024 count=1000000 # yes "droplet is awesome" | dd of=./setup.exe bs=1024 count=1000000
dd if=/dev/random of=./setup.exe bs=1024 count=1000000
zip TheGame.zip setup.exe zip TheGame.zip setup.exe
rm setup.exe rm setup.exe

View File

@ -24,7 +24,9 @@
"devDependencies": { "devDependencies": {
"@napi-rs/cli": "3.0.0-alpha.91", "@napi-rs/cli": "3.0.0-alpha.91",
"@types/node": "^22.13.10", "@types/node": "^22.13.10",
"ava": "^6.2.0" "ava": "^6.2.0",
"pretty-bytes": "^7.0.1",
"tsimp": "^2.0.12"
}, },
"ava": { "ava": {
"timeout": "3m", "timeout": "3m",
@ -51,8 +53,5 @@
"packageManager": "yarn@4.7.0", "packageManager": "yarn@4.7.0",
"repository": { "repository": {
"url": "git+https://github.com/Drop-OSS/droplet.git" "url": "git+https://github.com/Drop-OSS/droplet.git"
},
"dependencies": {
"tsimp": "^2.0.12"
} }
} }

View File

@ -12,6 +12,7 @@ __metadata:
"@napi-rs/cli": "npm:3.0.0-alpha.91" "@napi-rs/cli": "npm:3.0.0-alpha.91"
"@types/node": "npm:^22.13.10" "@types/node": "npm:^22.13.10"
ava: "npm:^6.2.0" ava: "npm:^6.2.0"
pretty-bytes: "npm:^7.0.1"
tsimp: "npm:^2.0.12" tsimp: "npm:^2.0.12"
languageName: unknown languageName: unknown
linkType: soft linkType: soft
@ -2432,6 +2433,13 @@ __metadata:
languageName: node languageName: node
linkType: hard linkType: hard
"pretty-bytes@npm:^7.0.1":
version: 7.0.1
resolution: "pretty-bytes@npm:7.0.1"
checksum: 10c0/14ffb503d2de3588042c722848062a4897e6faece1694e0c83ba5669ec003d73311d946d50d2b3c6099a6a306760011b8446ee3cf9cf86eca13a454a8f1c47cb
languageName: node
linkType: hard
"pretty-ms@npm:^9.1.0": "pretty-ms@npm:^9.1.0":
version: 9.2.0 version: 9.2.0
resolution: "pretty-ms@npm:9.2.0" resolution: "pretty-ms@npm:9.2.0"