示例工程 24-profiling-performance
24-profiling-performance/01-timeit-harness/README.md
# 01 · timeit-harness
**演示**:单次 `perf_counter` 计时容易被调度噪声影响;正确做法是 `timeit.repeat` 多次采样、取最小值,并报告样本分布。
**运行**:
```sh
uv run python examples/24-profiling-performance/01-timeit-harness/timeit_harness.py
```
**预期输出**(3.12.9,数值随机器波动):
```text
bad_single_ms: 0.278
samples: [0.522, 0.522, 0.525, 0.528, 0.526]
best_us: 5.22
worst_us: 5.28
spread_us: 0.06
```
**依赖**:仅标准库。
**注意**:`timeit` 会自动选择循环次数;显式 `number`/`repeat` 更可控。只报告最小值,别把单次结果当结论。