Align the bench table, which a tabwriter cannot
CI / test (push) Successful in 1m16s

Rows are printed as each concurrency level finishes, and a tabwriter lays out
only what has been flushed — so it aligned the header and the first row to
each other and every row after that to nothing. Fixed columns instead.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Ilker ManapandClaude Opus 5 committed 2026-09-16 09:59:55 +02:00
1 parent 5c837c531b
commit 378383dd69
1 file changed
+15 -7
+15 -7
View File
@@ -3,7 +3,6 @@ package cli
import (
"encoding/json"
"fmt"
"text/tabwriter"
"time"
"github.com/spf13/cobra"
@@ -49,8 +48,14 @@ func newBenchCmd(asJSON *bool) *cobra.Command {
}
cmd.PrintErrf("benchmarking %s against %s\n\n", cfg.Model, cfg.Target)
w := tabwriter.NewWriter(cmd.ErrOrStderr(), 0, 0, 2, ' ', 0)
fmt.Fprintln(w, "CONC\tREQ/S\tTOK/S\tTTFT p50\tTTFT p99\tTPOT p99\tWAIT\tKV\tSLO")
// Fixed columns rather than a tabwriter: rows are printed as each
// level finishes, and a tabwriter cannot align a column it has not
// seen the rest of yet — it lays out whatever has been flushed, so
// every row after the first came out ragged.
const row = "%-5s %-7s %-7s %-9s %-9s %-9s %-6s %-5s %s\n"
fmt.Fprintf(cmd.ErrOrStderr(), row,
"CONC", "REQ/S", "TOK/S", "TTFT p50", "TTFT p99", "TPOT p99", "WAIT", "KV", "SLO")
progress := func(s bench.Step) {
verdict := "ok"
if !s.MeetsSLO {
@@ -59,11 +64,14 @@ func newBenchCmd(asJSON *bool) *cobra.Command {
if s.Failed > 0 {
verdict = fmt.Sprintf("%d failed", s.Failed)
}
fmt.Fprintf(w, "%d\t%.1f\t%.0f\t%s\t%s\t%s\t%.1f\t%.0f%%\t%s\n",
s.Concurrency, s.RequestsPerSec, s.TokensPerSec,
fmt.Fprintf(cmd.ErrOrStderr(), row,
fmt.Sprint(s.Concurrency),
fmt.Sprintf("%.1f", s.RequestsPerSec),
fmt.Sprintf("%.0f", s.TokensPerSec),
ms(s.TTFT.P50), ms(s.TTFT.P99), ms(s.TPOT.P99),
s.Waiting, s.KVUsage*100, verdict)
_ = w.Flush()
fmt.Sprintf("%.1f", s.Waiting),
fmt.Sprintf("%.0f%%", s.KVUsage*100),
verdict)
}
res, err := bench.Run(cmd.Context(), cfg, progress)