[英]How do I interpret the output of `cargo bench`?
I benchmarked my Rust project with cargo bench
and see many numbers on the results... What do they mean?我用cargo bench
对我的Rust 项目进行了基准测试,结果看到了很多数字……它们是什么意思?
2 tests
test bench_few_core ... bench: 26,249,920 ns/iter (+/- 2,836,381)
test bench_one_core ... bench: 6,087,923 ns/iter (+/- 752,064)
For example for test bench_few_core
, I see:例如对于test bench_few_core
,我看到:
What do they all mean?它们都是什么意思?
I thought there should be 2 numbers per test: math expectation (or mean) and standard deviation.我认为每个测试应该有 2 个数字:数学期望(或平均值)和标准偏差。
The numbers are the median and the difference between the maximum and minimum , expressed using US-centric number styles (which use the comma as the thousands separator).数字是中位数以及最大值与最小值之间的差值,使用以美国为中心的数字样式(使用逗号作为千位分隔符)表示。
For your example:对于您的示例:
let median = bs.ns_iter_summ.median as usize;
let deviation = (bs.ns_iter_summ.max - bs.ns_iter_summ.min) as usize;
write!(
output,
"{:>11} ns/iter (+/- {})",
fmt_thousands_sep(median, ','),
fmt_thousands_sep(deviation, ',')
)
Note that there's various statistical work underlying the benchmarking , most obviously the fact that the upper and lower 5% of samples are truncated to reduce the effect of outliers.请注意, 基准测试背后有各种统计工作,最明显的事实是截断了上下 5% 的样本以减少异常值的影响。
Your example does show the two numbers you expect per test: the median and total deviation (ie max-min
) in nanoseconds per iteration.您的示例确实显示了您期望每次测试的两个数字:每次迭代以纳秒为单位的中值和总偏差(即max-min
)。
Note that for large numbers, it is standard practice in US English to write digits in groups of 3 separated by commas.请注意,对于大数字,美国英语的标准做法是以逗号分隔的 3 组数字书写。 For example, 26249920 is often written 26,249,920.例如,26249920 通常写成 26,249,920。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.