动态采样和可变批次


🌐 Dynamic sampling and variable batches

在测量样本期间调用 context.done() 会在该样本之后完成基准测试。这允许更高级的工具将 samples 视为最大值并实现动态采样策略。

🌐 Calling context.done() during a measured sample completes the benchmark after that sample. This allows a higher-level tool to treat samples as a maximum and implement a dynamic sampling policy.

不同样本之间的操作次数可能会有所不同。汇总统计将每个样本的 rate 视为同等权重的一次观测。特别是,summary.mean 是每个样本速率的算术平均值。它不是按以下方式计算的合并吞吐量:

🌐 The number of operations can differ between samples. Summary statistics treat each sample's rate as one equally weighted observation. In particular, summary.mean is the arithmetic mean of the per-sample rates. It is not the pooled throughput calculated as:

1_000_000_000 * sum(sample.operations) / sum(sample.duration_ns) 

当样本持续时间不同的时候,这两个值可能会有所不同,因为合并吞吐量会按每个样本的持续时间对每个样本速率进行加权。一个高级工具如果要更改批量大小,就应该选择与其分析相匹配的汇总方式。它可以从原始的 samples 计算合并吞吐量;操作计数应该作为 bigint 值求和,因为它们的总和可能超过 Number.MAX_SAFE_INTEGER,尽管每个计数本身不可能超过。

🌐 The two values can differ when sample durations vary because pooled throughput weights each per-sample rate by its duration. A higher-level tool that varies batch sizes should choose the aggregation that matches its analysis. It can calculate pooled throughput from the raw samples; operation counts should be summed as bigint values because their total can exceed Number.MAX_SAFE_INTEGER even though each count cannot.