From 9fd68e4307ea2e39b555668090839b5998eb4bc3 Mon Sep 17 00:00:00 2001 From: "moxey.eth" Date: Wed, 13 Mar 2024 13:13:49 +1100 Subject: [PATCH] chore: bench --- package.json | 1 + src/response.bench.tsx | 27 +++++++++++++++++++++++++++ src/utils/svgToPng.test.tsx | 2 +- 3 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 src/response.bench.tsx diff --git a/package.json b/package.json index 8cd68c3..769a920 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,7 @@ { "workspaces": ["src", "example"], "scripts": { + "bench": "vitest bench", "build": "bun run clean && tsc --project ./tsconfig.build.json && bun .scripts/postbuild.ts", "changeset": "changeset", "changeset:release": "bun run build && changeset publish", diff --git a/src/response.bench.tsx b/src/response.bench.tsx new file mode 100644 index 0000000..b7e1fd9 --- /dev/null +++ b/src/response.bench.tsx @@ -0,0 +1,27 @@ +import { bench, expect } from "vitest"; +import { ImageResponse } from "./response.js"; + +bench("png", async () => { + const response = new ImageResponse( +
+ hello +
, + ); + expect(response).toBeDefined(); + expect(new Uint8Array(await response.arrayBuffer())).toBeDefined(); +}); + +bench("svg", async () => { + const response = new ImageResponse( +
+ hello +
, + { format: "svg" }, + ); + expect(response).toBeDefined(); + expect(new Uint8Array(await response.arrayBuffer())).toBeDefined(); +}); diff --git a/src/utils/svgToPng.test.tsx b/src/utils/svgToPng.test.tsx index ed7967a..0a613c6 100644 --- a/src/utils/svgToPng.test.tsx +++ b/src/utils/svgToPng.test.tsx @@ -3,7 +3,7 @@ import { elementToSvg } from "./elementToSvg.js"; import { initializeWasm } from "./initializeWasm.js"; import { svgToPng } from "./svgToPng.js"; -test("default", async () => { +test.skip("default", async () => { await initializeWasm(); const svg = await elementToSvg(