Documentation
¶
Overview ¶
Package armbench measures benchmark arms with the attribution controls the mlxperf arena requires: interleaved execution, a mandatory identical duplicate-control arm, declared work equality, physics checks on reported byte traffic, and host qualification.
The harness prevents common attribution errors; it cannot make an uncontrolled host or semantically unequal arms comparable. Every experiment it runs produces a sealed experiment.Receipt. A receipt with refusals has no performance verdict — a refusal replaces a score, never annotates one.
The minimum experiment measures two identical functions plus their duplicate and requires that no winner be claimed:
work := func(context.Context) (armbench.Result, error) {
start := time.Now()
sum := 0
for i := 0; i < 100000; i++ {
sum += i
}
return armbench.Result{Elapsed: time.Since(start)}, nil
}
rcpt := armbench.Run(ctx, armbench.Experiment{
Rounds: 20,
Workload: experiment.Workload{ID: "spin/100k", WorkUnits: 100000},
Arms: []armbench.Arm{
{Name: "baseline", Kind: experiment.ArmBaseline, WorkUnits: 100000, Fn: work},
{Name: "candidate", Kind: experiment.ArmCandidate, WorkUnits: 100000, Fn: work},
{Name: "dup", Kind: experiment.ArmDuplicate, WorkUnits: 100000, Fn: work},
},
})
// rcpt.Verdict == experiment.VerdictNoWinner for identical arms.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Dispersions ¶
func Dispersions(r *experiment.Receipt) map[string]time.Duration
Dispersions returns the median absolute deviation of passing elapsed times per arm name: a robust within-arm spread used by the noise floor.
func Medians ¶
func Medians(r *experiment.Receipt) map[string]time.Duration
Medians returns the median elapsed time per arm name across passing samples. Failed samples do not contribute.
func Run ¶
func Run(ctx context.Context, x Experiment) (experiment.Receipt, error)
Run executes the experiment and returns its sealed receipt. It returns a non-nil error only for experiments that are not constructible at all (no arms); every other problem is recorded as a refusal in the receipt.
Example ¶
ExampleRun measures two identical arms plus their duplicate control. The duplicate-control gap is the noise floor, so identical arms produce no winner.
package main
import (
"context"
"fmt"
"time"
"github.com/tmc/apple/x/armbench"
"github.com/tmc/apple/x/experiment"
)
func main() {
work := func(context.Context) (armbench.Result, error) {
start := time.Now()
sum := 0
for i := 0; i < 100000; i++ {
sum += i
}
return armbench.Result{Elapsed: time.Since(start)}, nil
}
rcpt, err := armbench.Run(context.Background(), armbench.Experiment{
Warmup: 2,
Rounds: 30,
Workload: experiment.Workload{ID: "spin/100k", WorkUnits: 100000},
Arms: []armbench.Arm{
{Name: "baseline", Kind: experiment.ArmBaseline, WorkUnits: 100000, Fn: work},
{Name: "candidate", Kind: experiment.ArmCandidate, WorkUnits: 100000, Fn: work},
{Name: "dup", Kind: experiment.ArmDuplicate, WorkUnits: 100000, Fn: work},
},
})
if err != nil {
fmt.Println("error:", err)
return
}
fmt.Println(rcpt.Verdict)
if rcpt.Refused() {
for _, ref := range rcpt.Refusals {
fmt.Println(ref.Reason)
}
}
}
Output: no-winner
Types ¶
type Arm ¶
type Arm struct {
Name string
Kind experiment.ArmKind
WorkUnits int64 // work units this arm performs per execution
Fn func(ctx context.Context) (Result, error)
}
Arm is one named competitor in an experiment.
type Experiment ¶
type Experiment struct {
Workload experiment.Workload
Label string
Warmup int // unrecorded warmup executions per arm
Rounds int // recorded rounds per arm
Rotate bool // rotate starting arm each round instead of fixed order
Qualify func(ctx context.Context) error // host qualification; error contaminates the run
// MaxByteRate is the largest physically possible byte rate in bytes per
// second on this machine. A sample reporting more than this is refused as
// impossible. Zero disables the check.
MaxByteRate float64
Arms []Arm
}
Experiment declares a complete measurement.
type Result ¶
type Result struct {
Elapsed time.Duration
BytesByLocation map[string]int64 // byte traffic by named location
Output string // output digest or identity, when declared
}
Result is what an arm function reports for one execution. The harness records it verbatim; it does not trust anything the arm claims about its own relative speed.