[READ-ONLY] Mirror of https://github.com/bombshell-dev/tty. Platform independent 2D layout engine for terminal applications based on Clay
0

Configure Feed

Select the types of activity you want to include in your feed.

bench: add WASM init and startup timing benchmarks

+53 -1
+1
bench/mod.ts
··· 1 1 import "./input.bench.ts"; 2 2 import "./render.bench.ts"; 3 3 import "./ops.bench.ts"; 4 + import "./startup.bench.ts";
+51
bench/startup.bench.ts
··· 1 + import { Bench } from "tinybench"; 2 + import { withCodSpeed } from "@codspeed/tinybench-plugin"; 3 + import { bytes, compiled } from "../wasm.ts"; 4 + import { createTermNative } from "../term-native.ts"; 5 + import { createInputNative } from "../input-native.ts"; 6 + import { createTerm } from "../term.ts"; 7 + import { close, grow, open, text } from "../ops.ts"; 8 + import type { Op } from "../ops.ts"; 9 + 10 + const helloOps: Op[] = [ 11 + open("root", { layout: { width: grow(), height: grow(), direction: "ttb" } }), 12 + text("Hello, World!"), 13 + close(), 14 + ]; 15 + 16 + let bench = withCodSpeed(new Bench()); 17 + 18 + bench 19 + .add("wasm compile", async () => { 20 + await WebAssembly.compile(bytes); 21 + }) 22 + .add("wasm instantiate", async () => { 23 + const memory = new WebAssembly.Memory({ initial: 2 }); 24 + await WebAssembly.instantiate(compiled, { 25 + env: { memory }, 26 + clay: { 27 + measureTextFunction() {}, 28 + queryScrollOffsetFunction(ret: number) { 29 + const v = new DataView(memory.buffer); 30 + v.setFloat32(ret, 0, true); 31 + v.setFloat32(ret + 4, 0, true); 32 + }, 33 + }, 34 + }); 35 + }) 36 + .add("createTermNative (80x24)", async () => { 37 + await createTermNative(80, 24); 38 + }) 39 + .add("createInputNative", async () => { 40 + await createInputNative(50); 41 + }) 42 + .add("createTerm (80x24)", async () => { 43 + await createTerm({ width: 80, height: 24 }); 44 + }) 45 + .add("startup: createTerm + first render (80x24)", async () => { 46 + const term = await createTerm({ width: 80, height: 24 }); 47 + term.render(helloOps); 48 + }); 49 + 50 + await bench.run(); 51 + console.table(bench.table());
+1 -1
tasks/bundle-wasm.ts
··· 4 4 const base64 = encodeBase64(wasm); 5 5 6 6 const source = `const bin = atob("${base64}"); 7 - const bytes = new Uint8Array(bin.length); 7 + export const bytes = new Uint8Array(bin.length); 8 8 for (let i = 0; i < bin.length; i++) bytes[i] = bin.charCodeAt(i); 9 9 export const compiled = await WebAssembly.compile(bytes); 10 10 `;