Skip to content

Commit

Permalink
chore(lib): add benchmark for LazyWebSocket
Browse files Browse the repository at this point in the history
  • Loading branch information
hasundue committed Mar 21, 2024
1 parent 23c7344 commit 587aa14
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/deno.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
"./websockets": "./websockets.ts"
},
"publish": {
"exclude": ["*_test.ts"]
"exclude": [
"*_bench.ts",
"*_test.ts"
]
}
}
20 changes: 20 additions & 0 deletions lib/websockets_bench.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { MockWebSocket } from "@lophus/lib/testing";
import { LazyWebSocket } from "./websockets.ts";

Deno.bench("new", () => {
new LazyWebSocket("wss://localhost:8080");
});

Deno.bench("addEventListner", () => {
const lazy = new LazyWebSocket("wss://localhost:8080");
lazy.addEventListener("open", () => {});
});

Deno.bench("ready", async (b) => {
globalThis.WebSocket = MockWebSocket;
const lazy = new LazyWebSocket("wss://localhost:8080");
lazy.addEventListener("open", () => {});
b.start();
await lazy.ready();
b.end();
});

0 comments on commit 587aa14

Please sign in to comment.