"use client"; import { useState } from "react"; import { runBenchmark } from "@/lib/actions"; type BenchResult = { name: string; ms: number; rows?: number }; const badge = (ms: number) => ms < 1 ? "text-emerald-400" : ms < 5 ? "text-yellow-400" : ms < 20 ? "text-orange-400" : "text-red-400"; const bar = (ms: number, max: number) => Math.max(4, Math.min(100, (ms / max) * 100)); export default function QueryBench() { const [results, setResults] = useState([]); const [total, setTotal] = useState(0); const [loading, setLoading] = useState(false); const [runs, setRuns] = useState([]); const run = async () => { setLoading(true); try { const r = await runBenchmark(); setResults(r.results); setTotal(r.totalMs); setRuns((p) => [...p.slice(-9), r.totalMs]); } finally { setLoading(false); } }; const max = results.length ? Math.max(...results.map((r) => r.ms), 0.1) : 1; const avg = runs.length ? +(runs.reduce((a, b) => a + b, 0) / runs.length).toFixed(2) : 0; return (

⚡ Query Benchmark

SQLite query performance — direct server-side via Prisma (no API roundtrip)

{results.length > 0 && ( <>
Query Time Rows Speed
{results.map((r, i) => (
{r.name} {r.ms}ms {r.rows !== undefined ? r.rows : "—"}
))}
<1ms 1-5ms 5-20ms >20ms
{runs.length > 1 && (

Run History (total ms)

{runs.map((r, i) => { const h = Math.max(8, (r / Math.max(...runs)) * 100); return (
{r.toFixed(0)}
); })}
)} )}
); } function Stat({ label, value }: { label: string; value: string }) { return (

{value}

{label}

); }