engine: benchmark baseline (HolmeKim, RunScenario)
Manual baseline, not a CI gate: go test -bench=. -benchmem. First numbers on a Ryzen 7 5800X: HolmeKim ~25us/op (48KB, 671 allocs), full RunScenario ~45us/op (78KB, 681 allocs). Plenty fast until milestone 5 runs thousands of cascades per request; this is the 'before' picture for that work. b.Loop() (Go 1.24+) replaces the old 'for i := 0; i < b.N; i++' pattern and prevents the compiler optimising the loop body away.
This commit is contained in:
parent
2a5b78cb9a
commit
91ce0c1ca5
1 changed files with 30 additions and 0 deletions
30
internal/engine/bench_test.go
Normal file
30
internal/engine/bench_test.go
Normal file
|
|
@ -0,0 +1,30 @@
|
||||||
|
package engine
|
||||||
|
|
||||||
|
import "testing"
|
||||||
|
|
||||||
|
// Benchmarks are a baseline, not a gate: run them manually with
|
||||||
|
//
|
||||||
|
// go test -bench=. -benchmem ./internal/engine/
|
||||||
|
//
|
||||||
|
// The numbers become interesting in milestone 5, when the optimisation
|
||||||
|
// feature starts running thousands of cascades per request; comparing
|
||||||
|
// against this baseline catches accidental quadratic behaviour.
|
||||||
|
|
||||||
|
func BenchmarkHolmeKim(b *testing.B) {
|
||||||
|
config := DefaultConfig()
|
||||||
|
for b.Loop() {
|
||||||
|
_, err := HolmeKim(config.NumStudents, config.EdgesPerNode, config.TriangleProb, newRand(config.GraphSeed))
|
||||||
|
if err != nil {
|
||||||
|
b.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkRunScenario(b *testing.B) {
|
||||||
|
config := DefaultConfig()
|
||||||
|
for b.Loop() {
|
||||||
|
if _, err := RunScenario(config, StrategyMostConnected); err != nil {
|
||||||
|
b.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue