Skip to content

The all-in-one local AI studio for your desktop: chat, image and video generation and a coding agent in one free, open source app. Windows and Linux. No Docker, no terminal, no cloud required.

feat(benchmark): clear, export and finish the table without leaving the app

purple0daf3251e2ec
diff --git a/src/components/models/BenchmarkView.tsx b/src/components/models/BenchmarkView.tsx
index a296bfb9..5c04472b 100644
--- a/src/components/models/BenchmarkView.tsx
+++ b/src/components/models/BenchmarkView.tsx
@@ -1,7 +1,11 @@
-import { ArrowLeft, Trophy, Zap, Play, Square } from 'lucide-react'
+import { useState } from 'react'
+import { ArrowLeft, Trophy, Zap, Play, Square, Trash2, Download, ListChecks } from 'lucide-react'
import { useUIStore } from '../../stores/uiStore'
import { useModels } from '../../hooks/useModels'
-import { useBenchmarkStore, getLatestSpeed, getLeaderboard } from '../../stores/benchmarkStore'
+import {
+ useBenchmarkStore, getLatestSpeed, getLeaderboard,
+ toMarkdownReport, unbenchmarked, staleModels,
+} from '../../stores/benchmarkStore'
import { useBenchmark } from '../../hooks/useBenchmark'
export function BenchmarkView() {
@@ -15,11 +19,36 @@ export function BenchmarkView() {
const currentModel = useBenchmarkStore((s) => s.currentModel)
const currentStep = useBenchmarkStore((s) => s.currentStep)
const totalSteps = useBenchmarkStore((s) => s.totalSteps)
+ const clearResults = useBenchmarkStore((s) => s.clearResults)
+ const pruneMissing = useBenchmarkStore((s) => s.pruneMissing)
const { runBenchmark, stopBenchmark } = useBenchmark()
const leaderboard = getLeaderboard(results)
+ const [confirmClear, setConfirmClear] = useState(false)
// Only show text models (benchmarks don't apply to image/video)
const textModels = models.filter((m) => m.type === 'text')
+ const names = textModels.map((m) => m.name)
+ const pending = unbenchmarked(results, names)
+ const stale = staleModels(results, names)
+
+ /** Measure everything that has no run yet, one after another. The models
+ * share one GPU, so this is a queue, not a fan-out (M0j0Risin, D#21). */
+ const runPending = async () => {
+ for (const name of pending) {
+ if (useBenchmarkStore.getState().isRunning) break
+ await runBenchmark(name)
+ }
+ }
+
+ const exportReport = () => {
+ const md = toMarkdownReport(results, new Date().toISOString().slice(0, 16).replace('T', ' '))
+ const url = URL.createObjectURL(new Blob([md], { type: 'text/markdown' }))
+ const a = document.createElement('a')
+ a.href = url
+ a.download = 'lu-benchmark.md'
+ a.click()
+ URL.revokeObjectURL(url)
+ }
return (
<div className="h-full overflow-y-auto scrollbar-thin">
@@ -31,8 +60,62 @@ export function BenchmarkView() {
</button>
<Trophy size={16} className="text-amber-400" />
<h1 className="text-[0.8rem] font-semibold text-gray-800 dark:text-gray-200">Benchmark</h1>
+ <div className="ml-auto flex items-center gap-1">
+ {pending.length > 0 && (
+ <button
+ onClick={runPending}
+ disabled={isRunning}
+ title={`Benchmark the ${pending.length} model(s) with no result yet, one after another`}
+ className="flex items-center gap-1 px-2 py-1 rounded-md bg-gray-100 dark:bg-white/5 text-gray-600 dark:text-gray-400 text-[0.6rem] hover:bg-gray-200 dark:hover:bg-white/10 transition-colors disabled:opacity-30"
+ >
+ <ListChecks size={11} />
+ Benchmark {pending.length} remaining
+ </button>
+ )}
+ {leaderboard.length > 0 && (
+ <button
+ onClick={exportReport}
+ title="Download the table as Markdown"
+ className="flex items-center gap-1 px-2 py-1 rounded-md bg-gray-100 dark:bg-white/5 text-gray-600 dark:text-gray-400 text-[0.6rem] hover:bg-gray-200 dark:hover:bg-white/10 transition-colors"
+ >
+ <Download size={11} />
+ Export
+ </button>
+ )}
+ {leaderboard.length > 0 && (
+ <button
+ onClick={() => { if (confirmClear) { clearResults(); setConfirmClear(false) } else setConfirmClear(true) }}
+ onBlur={() => setConfirmClear(false)}
+ title="Delete every recorded benchmark run"
+ className={`flex items-center gap-1 px-2 py-1 rounded-md text-[0.6rem] transition-colors ${
+ confirmClear
+ ? 'bg-red-500/20 text-red-500'
+ : 'bg-gray-100 dark:bg-white/5 text-gray-600 dark:text-gray-400 hover:bg-red-500/15 hover:text-red-500'
+ }`}
+ >
+ <Trash2 size={11} />
+ {confirmClear ? 'Confirm' : 'Clear all'}
+ </button>
+ )}
+ </div>
</div>
+ {/* Results whose model is gone — the "out of whack" state from D#21. */}
+ {stale.length > 0 && (
+ <div className="mb-4 flex items-center justify-between gap-3 px-3 py-2 rounded-lg bg-amber-500/10 border border-amber-500/20">
+ <p className="text-[0.65rem] text-amber-600 dark:text-amber-400">
+ {stale.length} model{stale.length === 1 ? '' : 's'} in this table {stale.length === 1 ? 'is' : 'are'} no longer installed:{' '}
+ {stale.slice(0, 3).join(', ')}{stale.length > 3 ? ` and ${stale.length - 3} more` : ''}.
+ </p>
+ <button
+ onClick={() => pruneMissing(names)}
+ className="shrink-0 px-2 py-1 rounded-md bg-amber-500/15 text-amber-600 dark:text-amber-400 text-[0.6rem] hover:bg-amber-500/25 transition-colors"
+ >
+ Remove them
+ </button>
+ </div>
+ )}
+
{/* Leaderboard */}
{leaderboard.length > 0 && (
<div className="mb-6 p-4 rounded-xl bg-gray-50 dark:bg-white/[0.03] border border-gray-200 dark:border-white/5">
diff --git a/src/stores/__tests__/benchmark-management.test.ts b/src/stores/__tests__/benchmark-management.test.ts
new file mode 100644
index 00000000..3c9615c5
--- /dev/null
+++ b/src/stores/__tests__/benchmark-management.test.ts
@@ -0,0 +1,115 @@
+/**
+ * Benchmark housekeeping (M0j0Risin, D#21 2026-07-30, after a week of using
+ * the feature): clear the data from the UI instead of hunting for it in the
+ * file system, purge entries for models that no longer exist ("if you change
+ * models around, rename them, things get out of whack with older entries mixed
+ * in"), export the table in a form a model can read, and kick off the ones
+ * that have not been measured yet.
+ *
+ * Run: npx vitest run src/stores/__tests__/benchmark-management.test.ts
+ */
+import { describe, it, expect, beforeEach } from 'vitest'
+import {
+ useBenchmarkStore, toMarkdownReport, unbenchmarked, staleModels, getLeaderboard,
+} from '../benchmarkStore'
+import type { BenchmarkResult } from '../../lib/benchmark-prompts'
+
+const run = (modelName: string, tps: number, timestamp: number): BenchmarkResult =>
+ ({ modelName, tokensPerSec: tps, timestamp } as BenchmarkResult)
+
+const seed = (results: Record<string, BenchmarkResult[]>) =>
+ useBenchmarkStore.setState({ results })
+
+beforeEach(() => {
+ useBenchmarkStore.setState({ results: {}, isRunning: false, currentModel: null, currentStep: 0, totalSteps: 0 })
+})
+
+describe('clearing', () => {
+ it('clearResults empties the table', () => {
+ seed({ 'qwen3:8b': [run('qwen3:8b', 20, 1)] })
+ useBenchmarkStore.getState().clearResults()
+ expect(useBenchmarkStore.getState().results).toEqual({})
+ })
+
+ it('clearModel drops one model and leaves the rest', () => {
+ seed({ 'qwen3:8b': [run('qwen3:8b', 20, 1)], 'gemma4:e4b': [run('gemma4:e4b', 15, 1)] })
+ useBenchmarkStore.getState().clearModel('qwen3:8b')
+ expect(Object.keys(useBenchmarkStore.getState().results)).toEqual(['gemma4:e4b'])
+ })
+
+ it('clearModel on an unknown name changes nothing', () => {
+ seed({ 'qwen3:8b': [run('qwen3:8b', 20, 1)] })
+ useBenchmarkStore.getState().clearModel('not-here')
+ expect(Object.keys(useBenchmarkStore.getState().results)).toEqual(['qwen3:8b'])
+ })
+
+ it('pruneMissing keeps only models that are still installed', () => {
+ seed({
+ 'qwen3:8b': [run('qwen3:8b', 20, 1)],
+ 'old-model-renamed': [run('old-model-renamed', 9, 1)],
+ 'gemma4:e4b': [run('gemma4:e4b', 15, 1)],
+ })
+ useBenchmarkStore.getState().pruneMissing(['qwen3:8b', 'gemma4:e4b'])
+ expect(Object.keys(useBenchmarkStore.getState().results).sort()).toEqual(['gemma4:e4b', 'qwen3:8b'])
+ })
+
+ it('pruneMissing with nothing installed empties the table', () => {
+ seed({ 'qwen3:8b': [run('qwen3:8b', 20, 1)] })
+ useBenchmarkStore.getState().pruneMissing([])
+ expect(useBenchmarkStore.getState().results).toEqual({})
+ })
+})
+
+describe('what still needs measuring / what is stale', () => {
+ const results = {
+ 'qwen3:8b': [run('qwen3:8b', 20, 1)],
+ 'gone:7b': [run('gone:7b', 11, 1)],
+ 'empty:3b': [] as BenchmarkResult[],
+ }
+
+ it('unbenchmarked lists installed models with no run, including an empty array', () => {
+ expect(unbenchmarked(results, ['qwen3:8b', 'gemma4:e4b', 'empty:3b'])).toEqual(['gemma4:e4b', 'empty:3b'])
+ })
+
+ it('unbenchmarked is empty when everything has a result', () => {
+ expect(unbenchmarked(results, ['qwen3:8b'])).toEqual([])
+ })
+
+ it('staleModels lists recorded models that are not installed any more', () => {
+ expect(staleModels(results, ['qwen3:8b', 'empty:3b'])).toEqual(['gone:7b'])
+ })
+})
+
+describe('markdown export', () => {
+ it('renders a ranked table with runs and the latest pass', () => {
+ seed({
+ 'fast:3b': [run('fast:3b', 40, 1_000), run('fast:3b', 42, 2_000)],
+ 'slow:70b': [run('slow:70b', 4, 1_000)],
+ })
+ const md = toMarkdownReport(useBenchmarkStore.getState().results, '2026-08-01 12:00')
+
+ expect(md).toContain('# Local model benchmark')
+ expect(md).toContain('2026-08-01 12:00')
+ expect(md).toContain('| # | Model | Average t/s | Latest t/s | Runs |')
+ // Ranked fastest first, same order as the leaderboard on screen.
+ expect(md.indexOf('fast:3b')).toBeLessThan(md.indexOf('slow:70b'))
+ expect(md).toMatch(/\| 1 \| fast:3b \| 41 \|/)
+ expect(md).toMatch(/\| 2 \| slow:70b \| 4 \|/)
+ expect(md).toContain('3 runs across 2 models.')
+ })
+
+ it('says so plainly when there is nothing to export', () => {
+ const md = toMarkdownReport({}, '2026-08-01 12:00')
+ expect(md).toContain('No benchmark runs recorded yet.')
+ expect(md).not.toContain('| # |')
+ })
+
+ it('the export agrees with the leaderboard on screen', () => {
+ seed({ a: [run('a', 10, 1)], b: [run('b', 30, 1)], c: [run('c', 20, 1)] })
+ const results = useBenchmarkStore.getState().results
+ const order = getLeaderboard(results).map((e) => e.model)
+ const md = toMarkdownReport(results, 'now')
+ const positions = order.map((m) => md.indexOf(`| ${m} |`))
+ expect(positions).toEqual([...positions].sort((x, y) => x - y))
+ })
+})
diff --git a/src/stores/benchmarkStore.ts b/src/stores/benchmarkStore.ts
index 1ce796b9..29ced3f8 100644
--- a/src/stores/benchmarkStore.ts
+++ b/src/stores/benchmarkStore.ts
@@ -11,6 +11,14 @@ interface BenchmarkState {
addResult: (result: BenchmarkResult) => void
setRunning: (running: boolean, model?: string, total?: number) => void
setStep: (step: number) => void
+ /** Drop every recorded run. */
+ clearResults: () => void
+ /** Drop the runs for one model (renamed, re-quantized, deleted). */
+ clearModel: (modelName: string) => void
+ /** Drop runs for models that are no longer installed. M0j0Risin, D#21
+ * 2026-07-30: "if you change models around, rename them, things get out of
+ * whack with older entries mixed in". */
+ pruneMissing: (installedModelNames: string[]) => void
}
export const useBenchmarkStore = create<BenchmarkState>()(
@@ -40,11 +48,79 @@ export const useBenchmarkStore = create<BenchmarkState>()(
}),
setStep: (step) => set({ currentStep: step }),
+
+ clearResults: () => set({ results: {} }),
+
+ clearModel: (modelName) => set((s) => {
+ const { [modelName]: _dropped, ...rest } = s.results
+ return { results: rest }
+ }),
+
+ pruneMissing: (installedModelNames) => set((s) => {
+ const installed = new Set(installedModelNames)
+ return {
+ results: Object.fromEntries(
+ Object.entries(s.results).filter(([model]) => installed.has(model)),
+ ),
+ }
+ }),
}),
{ name: 'lu-benchmark-store' }
)
)
+/** Models with no recorded run yet — what a "measure everything left" pass
+ * works through. */
+export function unbenchmarked(results: Record<string, BenchmarkResult[]>, modelNames: string[]): string[] {
+ return modelNames.filter((m) => !(results[m]?.length))
+}
+
+/** Models that hold runs but are not installed any more. */
+export function staleModels(results: Record<string, BenchmarkResult[]>, installedModelNames: string[]): string[] {
+ const installed = new Set(installedModelNames)
+ return Object.keys(results).filter((m) => !installed.has(m))
+}
+
+/**
+ * The whole benchmark table as Markdown, so it can be pasted into a report or
+ * handed to a model (M0j0Risin, D#21: "it's possible to screen scrape it and
+ * get a useful report but it would be cool to be able to export from the app").
+ * Ranked like the leaderboard, with the run count and the latest session next
+ * to the average so a single fast run cannot masquerade as a stable result.
+ */
+export function toMarkdownReport(
+ results: Record<string, BenchmarkResult[]>,
+ generatedAt: string,
+): string {
+ const board = getLeaderboard(results)
+ const lines = [
+ '# Local model benchmark',
+ '',
+ `Generated ${generatedAt} by Locally Uncensored.`,
+ '',
+ ]
+ if (board.length === 0) {
+ lines.push('No benchmark runs recorded yet.', '')
+ return lines.join('\n')
+ }
+ lines.push(
+ '| # | Model | Average t/s | Latest t/s | Runs |',
+ '| --- | --- | ---: | ---: | ---: |',
+ )
+ board.forEach((entry, i) => {
+ const latest = getLatestSpeed(results, entry.model)
+ lines.push(`| ${i + 1} | ${entry.model} | ${entry.avgTps} | ${latest ?? '-'} | ${entry.runs} |`)
+ })
+ lines.push(
+ '',
+ `${board.reduce((s, e) => s + e.runs, 0)} runs across ${board.length} models.`,
+ '',
+ 'Average is every recorded run. Latest is the most recent benchmark pass.',
+ '',
+ )
+ return lines.join('\n')
+}
+
/** Get average speed for a model (standalone, not a store method) */
export function getAverageSpeed(results: Record<string, BenchmarkResult[]>, modelName: string): number | null {
const runs = results[modelName]