| 100 | |
| 101 | |
| 102 | def evaluate(case: BenchCase, result: dict[str, Any]) -> tuple[bool, str]: |
| 103 | edges = result.get("edges_captured", 0) |
| 104 | periods = result.get("periods", 0) |
| 105 | mean_ns = result.get("period_mean_ns", 0) |
| 106 | sigma_ns = result.get("period_sigma_ns", 0) |
| 107 | min_ns = result.get("period_min_ns", 0) |
| 108 | max_ns = result.get("period_max_ns", 0) |
| 109 | if periods < 5: |
| 110 | return False, ( |
| 111 | f"only {periods} periods captured in {case.duration_ms} ms " |
| 112 | f"(edges={edges}) — capture path likely not working yet" |
| 113 | ) |
| 114 | mean_low = case.expected_period_ns * (1.0 - case.mean_tolerance_pct / 100.0) |
| 115 | mean_high = case.expected_period_ns * (1.0 + case.mean_tolerance_pct / 100.0) |
| 116 | if not (mean_low <= mean_ns <= mean_high): |
| 117 | return False, ( |
| 118 | f"mean {mean_ns} ns outside ±{case.mean_tolerance_pct}% of " |
| 119 | f"{case.expected_period_ns} ns (range {mean_low:.0f}..{mean_high:.0f})" |
| 120 | ) |
| 121 | if sigma_ns > case.sigma_max_ns: |
| 122 | return False, f"sigma {sigma_ns} ns exceeds {case.sigma_max_ns} ns" |
| 123 | return True, ( |
| 124 | f"periods={periods}, mean={mean_ns} ns, sigma={sigma_ns} ns, " |
| 125 | f"min={min_ns} ns, max={max_ns} ns" |
| 126 | ) |
| 127 | |
| 128 | |
| 129 | def main() -> int: |