## MEASUREMENT ONLY — per-tick cost of the rack-registered TM pattern gun ## (id 14, radial mode) in isolation, following the `runPerGun` pattern of ## `measure_parallel_vbullet_cost.nim`. ## ## Drives ONE gun through a real DrussGT fixture with a one-gun VirtualTracker, ## timing `predict` (4 power bins/tick) and `onResult` (one call per resolved ## virtual bullet) separately, then reports ms/tick against the ~13.16 ms live ## budget (76 ticks/s). Tsetlin is measured the same way as the reference the ## brief quotes (~5.3 ms/tick). ## ## Usage: ## nim c -r -d:release common_libs/tests/measure_tm_pattern_cost.nim import std/[os, strformat, tables, math, times, monotimes, random] import gun_harness/offline_range import gun_harness/gun_interface import gun_harness/virtual_bullets as vb import guns/tm_pattern import guns/tsetlin const RepoRoot = currentSourcePath().parentDir.parentDir.parentDir FixturePath = RepoRoot / "tools" / "fixtures" / "tr_drussgt_vs_crazy.jsonl" type CostResult = object predictNs: int64 onResultNs: int64 ticks: int predictCalls: int onCalls: int proc measureGun(fx: Fixture, predictCb: proc(state: WorldState, bulletSpeed: float): GunPrediction {.closure.}, resultCb: proc(e: FeedbackEvent) {.closure.}, metric: BulletMetric, warmup, measure: int): CostResult = var tracker = vb.initTracker(1, metric) let acc = new(CostResult) let ticks = fx.states.len for si in 0..= warmup and si < warmup + measure: acc.onResultNs += (s1 - s0).inNanoseconds inc acc.onCalls) if si >= warmup and si < warmup + measure: inc acc.ticks acc.predictNs += (t1 - t0).inNanoseconds inc acc.predictCalls, len(vb.PowerBins) result = acc[] proc makeTmRadial(fx: Fixture, metric: BulletMetric, warmup, measure: int): CostResult = let g = new(TmPatternGun) g[] = initTmRadialGun() randomize(1) result = measureGun(fx, proc(state: WorldState, bulletSpeed: float): GunPrediction = g[].predict(state, bulletSpeed), proc(e: FeedbackEvent) = g[].onResult(e), metric, warmup, measure) echo fmt" TMPattern(radial): obs={g[].totalObs} labelMiss={g[].labelMisses} " & fmt"traceMiss={g[].traceMisses} radAcc={g[].radCorrect}/{g[].radTotal}" var lab = "" var maj = 0 var tot = 0 for c in 0..