Skip to content

Commit

Permalink
chore: add benchmark script
Browse files Browse the repository at this point in the history
related to #387
  • Loading branch information
pi0 committed May 15, 2024
1 parent f70104e commit d84bcc6
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 0 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@
"ioredis-mock": "^8.9.0",
"jiti": "^1.21.0",
"jsdom": "^24.0.0",
"mitata": "^0.1.11",
"monaco-editor": "^0.48.0",
"mongodb": "^6.6.1",
"mongodb-memory-server": "^9.2.0",
Expand Down
8 changes: 8 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 37 additions & 0 deletions test/server.bench.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { bench, run } from "mitata";
import { listen } from "listhen";
import { $fetch } from "ofetch";
import { createStorage } from "../src/index.ts";
import { createStorageServer } from "../src/server.ts";

async function main() {
const storage = createStorage();

for (let i = 0; i < 10; i++) {
for (let j = 0; j < 10; j++) {
await storage.set(`key:${i}:${j}`, `value-${i}-${j}`);
}
}

const storageServer = createStorageServer(storage, {});

const { close, url: serverURL } = await listen(storageServer.handle, {
port: { random: true },
});

const fetchStorage = (url: string, options?: any) =>
$fetch(url, { baseURL: serverURL, ...options });

bench("storage server", async () => {
await Promise.all([
await fetchStorage(`/key:`),

Check failure on line 27 in test/server.bench.ts

View workflow job for this annotation

GitHub Actions / ci

Promise in `Promise.all()` should not be awaited

Check failure on line 27 in test/server.bench.ts

View workflow job for this annotation

GitHub Actions / autofix

Promise in `Promise.all()` should not be awaited
await fetchStorage(`/key:0:0`),

Check failure on line 28 in test/server.bench.ts

View workflow job for this annotation

GitHub Actions / ci

Promise in `Promise.all()` should not be awaited

Check failure on line 28 in test/server.bench.ts

View workflow job for this annotation

GitHub Actions / autofix

Promise in `Promise.all()` should not be awaited
]);
});

await run();

await close();
}

main();

Check failure on line 37 in test/server.bench.ts

View workflow job for this annotation

GitHub Actions / ci

Prefer top-level await over an async function `main` call

Check failure on line 37 in test/server.bench.ts

View workflow job for this annotation

GitHub Actions / autofix

Prefer top-level await over an async function `main` call

0 comments on commit d84bcc6

Please sign in to comment.