|
| 1 | +// Higher-is-better companion to BenchChart for the HTTP requests/sec result |
| 2 | +// (bench/rps.sh). Data is inline because it comes from an external load |
| 3 | +// generator (autocannon), not the bench/run.sh JSON the other charts read. |
| 4 | +// |
| 5 | +// NOTE: the @opentf/web compiler rewrites `.map()` into a reactive list helper, |
| 6 | +// so non-render computations must use plain loops, and dynamic styles must be |
| 7 | +// objects (a style string becomes Object.assign(..., str)). |
| 8 | +const LABELS = { esrun: "esrun", bun: "Bun", node: "Node.js", deno: "Deno" }; |
| 9 | + |
| 10 | +// req/s, Hono hello-world over autocannon -c 100, one Linux x86-64 box. |
| 11 | +const ROW = { esrun: 40220, deno: 40150, bun: 39686, node: 33358 }; |
| 12 | +const ORDER = ["esrun", "deno", "bun", "node"]; |
| 13 | + |
| 14 | +function fmt(v) { |
| 15 | + return (v / 1000).toFixed(1) + "k"; |
| 16 | +} |
| 17 | + |
| 18 | +export default function RpsChart() { |
| 19 | + let max = 0; |
| 20 | + let winner = null; |
| 21 | + for (const rt of ORDER) { |
| 22 | + if (ROW[rt] > max) { |
| 23 | + max = ROW[rt]; |
| 24 | + winner = rt; |
| 25 | + } |
| 26 | + } |
| 27 | + |
| 28 | + return ( |
| 29 | + <div> |
| 30 | + <div className="mb-1.5 flex items-baseline justify-between"> |
| 31 | + <span className="text-xs font-semibold uppercase tracking-wider text-zinc-500"> |
| 32 | + HTTP requests/sec · Hono hello-world |
| 33 | + </span> |
| 34 | + <span className="text-[10px] text-zinc-400">higher is better</span> |
| 35 | + </div> |
| 36 | + <div className="space-y-1.5"> |
| 37 | + {ORDER.map((rt) => { |
| 38 | + const pct = Math.max((ROW[rt] / max) * 100, 2); |
| 39 | + const isWin = rt === winner; |
| 40 | + return ( |
| 41 | + <div className="flex items-center gap-2.5"> |
| 42 | + <span className="w-14 shrink-0 text-right text-[11px] font-medium text-zinc-600"> |
| 43 | + {LABELS[rt]} |
| 44 | + </span> |
| 45 | + <div className="h-3 flex-1 overflow-hidden rounded-full bg-zinc-100"> |
| 46 | + <div |
| 47 | + className={ |
| 48 | + isWin |
| 49 | + ? "h-full rounded-full bg-emerald-500" |
| 50 | + : "h-full rounded-full bg-zinc-300" |
| 51 | + } |
| 52 | + style={{ width: pct + "%" }} |
| 53 | + /> |
| 54 | + </div> |
| 55 | + <span |
| 56 | + className={ |
| 57 | + isWin |
| 58 | + ? "w-14 shrink-0 text-right text-[11px] font-semibold tabular-nums text-emerald-700" |
| 59 | + : "w-14 shrink-0 text-right text-[11px] tabular-nums text-zinc-500" |
| 60 | + } |
| 61 | + > |
| 62 | + {fmt(ROW[rt])} |
| 63 | + </span> |
| 64 | + </div> |
| 65 | + ); |
| 66 | + })} |
| 67 | + </div> |
| 68 | + </div> |
| 69 | + ); |
| 70 | +} |
0 commit comments