普贤教程 › 包参考
bench 包
微基准计时
| 项 | 值 |
|---|---|
| 包名 | bench |
| 版本 | 0.2.0 |
| 可用版本 | 0.1.0 / 0.2.0 |
| 入口 | bench.px |
| 分类 | 可观测与测试 |
| 文件数 / 行数 | 1 / 76 |
安装与引入
bash
pxpkg init # 首次 pxpkg add bench@0.2.0 pxpkg install
px
import bench所属分类教程:可观测与测试
公开接口
| 函数 | 参数 |
|---|---|
bn_time | f, n |
其余 4 个 def(内部与辅助,可直接调用但不属稳定接口)
| 函数 | 参数 |
|---|---|
bn_time_ms | f, n |
bn_compare | fa, fb, n, name_a="a", name_b="b" |
bn_stats | f, n, runs=5 |
bn_format | ms |
包内说明(源码头注释)
text
============================================================
普贤生态库:registry/bench —— 微基准计时
------------------------------------------------------------
纯函数库(IO:now_ns 计时,无状态),编译(px build)与解释(px run)双模式一致。
bn_time(f, n) → Ok({total_ns, ns_per_op, ops_per_sec}) | Err
n <= 0 → Err;时间源 = now_ns(墙钟纳秒,非 CPU 时间)。解释轨性能远低于
编译轨属预期(PX-DEF-024 同族),bench 主要用于编译轨产物对比。
============================================================