bench

package
v0.8.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 2, 2026 License: MIT Imports: 20 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

bench

bench/ runs coding tasks through the real harness (local sandbox, coding profile) and reports pass/fail, steps, tool calls, tokens, prompt-cache hits, wall time and memory. Each task has hidden tests restored before verification and a reference solution; go test ./bench proves every task fails untouched and passes with its solution, and exercises the runner with a scripted model (no network).

bench -list
bench -tasks go-fix-bugs,py-fix-bugs -n 3 -out run.json     # model from LLM_* env
bench -tier hard -n 5 -parallel 4 -out hard.json             # the hard tier, 5 repeats, 4 runs at once
bench -price-in 3 -price-cached 0.3 -price-out 15 ...        # USD per 1M tokens: adds an estimated cost
bench -compare before.json after.json                        # before/after a harness change
go test -tags live ./bench -run TestLive -v                  # same, as a test (BENCH_TASKS, BENCH_OUT)

Tasks have a tier: easy (six small tasks a small model solves in a few steps) and hard (multi-file features, a bug far from its symptom, a data race checked with go test -race, a cross-package refactor, repository conventions in AGENTS.md, a config format migration, a misleading README, a Node task; Python/Node/make tasks are skipped when the program is missing). Use -tier easy|hard to filter and bench -list to see the tier.

Reports are meant for repeats (-n): the Markdown output has a per-task table with the pass rate (pass 2/3), mean/median steps and tokens, and the JSON report keeps every run plus the per-task aggregates. Besides total input tokens it reports uncached input per step, (input - cached) / steps, which is what prompt caching does not absorb, and, when prices are given, an estimated cost; -compare shows both. -parallel N runs N tasks at once (each run has its own working directory and state); wall time is per run, but peak RSS is process-wide, so use -parallel 1 for memory comparisons.

Documentation

Overview

Package bench runs coding tasks through the real harness (local sandbox, coding profile) against a model and reports pass/fail with the cost: steps, tool calls, tokens, prompt-cache hits, wall time and memory.

A Task is a small repository (Files), a prompt, and a check that decides whether the job was done: Verify, a shell command run in the repository after the agent finished (exit 0 = pass), after Hidden files — the original tests — are written back so an agent cannot pass by weakening them; and/or Answer, regular expressions that must all match the final answer (questions about the code). Solution is a reference fix: the offline tests apply it to prove each task is solvable and fails before the fix.

Offline (scripted model) the package is a regular test; against a live model use cmd/bench or `go test -tags live ./bench`.

Index

Constants

View Source
const (
	TierEasy = "easy"
	TierHard = "hard"
	// TierLong tasks need 50+ steps (compaction, masking); `-tier long` runs them.
	TierLong = "long"
)

Difficulty tiers.

Variables

This section is empty.

Functions

func Check

func Check(ctx context.Context, t Task, dir, answer string) (ok bool, output string)

Check applies t's hidden files in dir and reports whether the task's checks hold for answer.

func Compare

func Compare(w io.Writer, before, after Report)

Compare renders the change from a baseline report to a new one, per task and in total (pass rate, mean steps, mean input tokens, cache hit %, uncached tokens per step, seconds, and cost when either report has prices), for before/after runs of a harness change.

func Markdown

func Markdown(w io.Writer, rs []Result)

Markdown renders results as a table with a total row, then a per-task table of pass rates.

func MarkdownWith

func MarkdownWith(w io.Writer, rs []Result, p Prices)

MarkdownWith is Markdown with the estimated cost at p (shown when any price is set).

func Materialize

func Materialize(dir string, files ...map[string]string) error

Materialize writes files under dir.

func Missing

func Missing(t Task) []string

Missing returns the programs of t that are not on PATH.

func Names

func Names() string

Names returns the task names of the built-in set, comma separated (for flag help).

func WriteJSON

func WriteJSON(path, model string, rs []Result) error

WriteJSON writes the report to path.

func WriteJSONWith

func WriteJSONWith(path, model string, rs []Result, p Prices) error

WriteJSONWith is WriteJSON recording the prices and the estimated cost.

Types

type Options

type Options struct {
	// Timeout bounds the whole task (default 10 minutes).
	Timeout time.Duration
	// MaxSteps overrides AGENT_MAX_STEPS (0: keep).
	MaxSteps int
	// Keep leaves the working directory in place and records it in Result.Dir.
	Keep bool
	// NoCacheKey sends no prompt_cache_key (some routers route on it).
	NoCacheKey bool
}

Options tune a run.

type Prices

type Prices struct {
	In     float64 `json:"in"`
	Cached float64 `json:"cached"`
	Out    float64 `json:"out"`
}

Prices are USD per million tokens; the zero value means "unpriced" (no cost is shown).

func (Prices) Cost

func (p Prices) Cost(r Result) float64

Cost estimates the USD cost of a run: uncached input at In, cached input at Cached, output at Out.

func (Prices) Set

func (p Prices) Set() bool

Set reports whether any price is given.

type Report

type Report struct {
	Model   string      `json:"model"`
	Prices  *Prices     `json:"prices,omitempty"`
	Summary Summary     `json:"summary"`
	Tasks   []TaskStats `json:"tasks,omitempty"`
	Results []Result    `json:"results"`
}

Report is the JSON written by WriteJSON. Results keeps every run (repeats included); Tasks is the per-task aggregate.

func ReadReport

func ReadReport(path string) (Report, error)

ReadReport loads a report written by WriteJSON.

type Result

type Result struct {
	Task  string `json:"task"`
	Model string `json:"model"`
	// Passed: the run finished and the task's checks held.
	Passed bool `json:"passed"`
	// Status is "finished", or the RUN_ERROR code / failure that ended the run.
	Status string `json:"status"`
	// Detail is the last warning the harness logged for the run (why a run failed; the event only says "model_error").
	Detail       string `json:"detail,omitempty"`
	VerifyOutput string `json:"verifyOutput,omitempty"`
	FinalAnswer  string `json:"finalAnswer,omitempty"`

	Steps      int            `json:"steps"`
	ToolCalls  int            `json:"toolCalls"`
	ToolErrors int            `json:"toolErrors"`
	Tools      map[string]int `json:"tools,omitempty"`

	InputTokens  int     `json:"inputTokens"`
	OutputTokens int     `json:"outputTokens"`
	CachedTokens int     `json:"cachedTokens"`
	CacheHitPct  float64 `json:"cacheHitPct"`
	// UncachedTokens is InputTokens - CachedTokens; UncachedPerStep divides it by Steps.
	UncachedTokens  int     `json:"uncachedTokens"`
	UncachedPerStep float64 `json:"uncachedPerStep"`

	WallSeconds float64 `json:"wallSeconds"`
	// HeapMiB and SysMiB are the Go heap in use and memory obtained from the OS at the end of the run;
	// MaxRSSMiB is the process peak so far (it only grows across the tasks of one process).
	HeapMiB   float64 `json:"heapMiB"`
	SysMiB    float64 `json:"sysMiB"`
	MaxRSSMiB float64 `json:"maxRSSMiB"`

	Dir string `json:"dir,omitempty"`
}

Result is what one run of one task cost and achieved.

func Run

func Run(ctx context.Context, base *config.Config, models llm.Factory, t Task, o Options) Result

Run executes t through the harness with the local sandbox and the coding profile and returns the result. base supplies the model configuration (config.Load); models, when non-nil, replaces the real model client (offline tests). The run's working directory is a fresh temporary one.

type Suite

type Suite struct {
	Config *config.Config
	// ModelsFor returns the model factory of a run (nil: the real model from Config). It is called once
	// per run, possibly from several goroutines.
	ModelsFor func(Task) llm.Factory
	Options   Options
	// Parallel is the number of runs in flight (default 1).
	Parallel int
	// Skip is called (serialized) for each task skipped because a program it needs is missing.
	Skip func(t Task, missing []string)
	// Progress is called (serialized) when a run finishes; run is 1-based.
	Progress func(t Task, run, n int, r Result)
}

Suite runs tasks, N times each, optionally several at once.

Parallel runs share one process: wall time is still per run, but MaxRSSMiB (and to a lesser degree HeapMiB/SysMiB) are process-wide and cannot be attributed to a single run.

func (Suite) Run

func (s Suite) Run(ctx context.Context, tasks []Task, n int) []Result

Run executes every task n times and returns the results in task order, then run order.

type Summary

type Summary struct {
	Runs            int     `json:"runs"`
	Passed          int     `json:"passed"`
	PassRate        float64 `json:"passRate"`
	Steps           int     `json:"steps"`
	ToolCalls       int     `json:"toolCalls"`
	ToolErrors      int     `json:"toolErrors"`
	InputTokens     int     `json:"inputTokens"`
	OutputTokens    int     `json:"outputTokens"`
	CachedTokens    int     `json:"cachedTokens"`
	CacheHitPct     float64 `json:"cacheHitPct"`
	UncachedTokens  int     `json:"uncachedTokens"`
	UncachedPerStep float64 `json:"uncachedPerStep"`
	// CostUSD is the estimated cost; zero unless prices were given.
	CostUSD     float64 `json:"costUSD,omitempty"`
	WallSeconds float64 `json:"wallSeconds"`
	MaxRSSMiB   float64 `json:"maxRSSMiB"`
}

Summary aggregates the results of a benchmark.

func Summarize

func Summarize(rs []Result) Summary

Summarize totals results (skipped runs are not counted by the caller).

func SummarizeWith

func SummarizeWith(rs []Result, p Prices) Summary

SummarizeWith is Summarize plus the estimated cost at p.

type Task

type Task struct {
	Name string
	// Tier is TierEasy (the default when empty) or TierHard; see TierOf.
	Tier   string
	Prompt string
	// Files is the starting repository (path → content).
	Files map[string]string
	// Hidden files are written over the repository before Verify runs.
	Hidden map[string]string
	// Verify is a bash command run in the repository; exit 0 means the task is done. Empty: only Answer counts.
	Verify string
	// Answer regexps must all match the final answer.
	Answer []string
	// Solution files, applied over Files, make Verify (and Hidden) pass.
	Solution map[string]string
	// SolutionAnswer is a final answer that satisfies Answer.
	SolutionAnswer string
	// Needs lists the programs the task needs on PATH (go, python3, make).
	Needs []string
}

Task is one benchmark job.

func Builtin

func Builtin() []Task

Builtin returns the built-in tasks, by name.

func FilterTier

func FilterTier(ts []Task, tier string) []Task

FilterTier keeps the tasks of one tier ("easy", "hard" or "long"). An empty tier or "all" keeps the easy and hard tasks: the long ones need 50+ steps and are only run when asked for.

func LongTasks

func LongTasks() []Task

LongTasks returns the long-session tasks: they need 50+ steps and, with a small context window, compaction and masking (set LLM_CONTEXT_WINDOWS=<model>=32000 to force it). They are generated programmatically so the repositories are big enough to be explored and edited file by file.

func Select

func Select(names []string) (tasks []Task, missing []string)

Select returns the named tasks (all when names is empty); unknown names are returned in missing.

func (Task) TierOf

func (t Task) TierOf() string

TierOf returns the task's tier (easy when unset).

type TaskStats

type TaskStats struct {
	Task   string `json:"task"`
	Runs   int    `json:"runs"`
	Passed int    `json:"passed"`
	// PassRate is Passed/Runs.
	PassRate     float64 `json:"passRate"`
	MeanSteps    float64 `json:"meanSteps"`
	MedianSteps  float64 `json:"medianSteps"`
	MeanTokens   float64 `json:"meanTokens"`   // input + output
	MedianTokens float64 `json:"medianTokens"` // input + output
	MeanUncached float64 `json:"meanUncachedPerStep"`
	MeanCostUSD  float64 `json:"meanCostUSD,omitempty"`
}

TaskStats aggregates the repeated runs of one task.

func PerTask

func PerTask(rs []Result, p Prices) []TaskStats

PerTask groups results by task (sorted by name) and returns the pass rate, mean and median steps and tokens of the runs of each.

Directories

Path Synopsis
Package swebench turns SWE-bench instances (https://www.swebench.com) into bench tasks and scores the resulting repositories the way SWE-bench does.
Package swebench turns SWE-bench instances (https://www.swebench.com) into bench tasks and scores the resulting repositories the way SWE-bench does.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL