如果你比较苹果和梨,这不是回归。在这种情况下,两次。
第一对苹果/梨
这fixed
是苹果,scientific
是梨。
不仅结果输出明显不同,而且达到结果需要不同的步骤。
重要scientific
的是涉及log10
输入值的取值,以便确定小数点前以 10 为基数的数字的大小:
默认情况下,real_policies 调用“便宜”的判断:
static int floatfield(T n)
{
if (traits::test_zero(n))
return fmtflags::fixed;
T abs_n = traits::get_absolute_value(n);
return (abs_n >= 1e5 || abs_n < 1e-3)
? fmtflags::scientific : fmtflags::fixed;
}
因此,如果您选择一种无论如何都会切换到科学的格式,您可以看到差异消失:123456.123456
而不是12345.12345
...:
clock resolution: mean is 16.9199 ns (40960002 iterations)
benchmarking format_performance_direct_string
collecting 100 samples, 1 iterations each, in estimated 4.7784 ms
mean: 238.81 ns, lb 187.22 ns, ub 493.46 ns, ci 0.95
std dev: 507.559 ns, lb 5.36317 ns, ub 1111.94 ns, ci 0.95
found 11 outliers among 100 samples (11%)
variance is severely inflated by outliers
benchmarking format_performance_direct_string_with_policy
collecting 100 samples, 96 iterations each, in estimated 1699.2 μs
mean: 173.927 ns, lb 172.764 ns, ub 176.939 ns, ci 0.95
std dev: 8.33706 ns, lb 0.256875 ns, ub 16.9312 ns, ci 0.95
found 2 outliers among 100 samples (2%)
variance is moderately inflated by outliers
benchmarking format_performance_string
collecting 100 samples, 84 iterations each, in estimated 1705.2 μs
mean: 312.646 ns, lb 311.027 ns, ub 314.819 ns, ci 0.95
std dev: 9.42479 ns, lb 7.32668 ns, ub 15.2546 ns, ci 0.95
found 1 outliers among 100 samples (1%)
variance is moderately inflated by outliers
benchmarking format_performance_string_with_policy
collecting 100 samples, 31 iterations each, in estimated 1736 μs
mean: 193.572 ns, lb 192.257 ns, ub 200.032 ns, ci 0.95
std dev: 12.8586 ns, lb 0.322008 ns, ub 30.6708 ns, ci 0.95
found 4 outliers among 100 samples (4%)
variance is severely inflated by outliers
如您所见,自定义策略(可预测)要快得多
作为互动链接:
第二对苹果/梨
这会出现在您将精度固定为 15 位的地方。
通过使用两个策略的单独头对头基准,实际上还可以执行精度: http: //paste.ubuntu.com/13087371/您可以看到这不仅失去了将格式固定为的好处scientific
见上图:
clock resolution: mean is 18.6041 ns (40960002 iterations)
benchmarking format_performance_direct_string_with_policy
collecting 100 samples, 1 iterations each, in estimated 1892.9 μs
mean: 228.83 ns, lb 179.9 ns, ub 471.84 ns, ci 0.95
std dev: 483.67 ns, lb 2.29965 ns, ub 1153.98 ns, ci 0.95
found 14 outliers among 100 samples (14%)
variance is severely inflated by outliers
benchmarking format_performance_direct_string_with_policy15
collecting 100 samples, 45 iterations each, in estimated 1858.5 μs
mean: 418.697 ns, lb 410.976 ns, ub 438.865 ns, ci 0.95
std dev: 58.0984 ns, lb 24.1313 ns, ub 115.549 ns, ci 0.95
found 6 outliers among 100 samples (6%)
variance is severely inflated by outliers
benchmarking format_performance_string_with_policy
collecting 100 samples, 87 iterations each, in estimated 1870.5 μs
mean: 262.057 ns, lb 254.73 ns, ub 269.354 ns, ci 0.95
std dev: 37.2502 ns, lb 31.1261 ns, ub 50.5813 ns, ci 0.95
found 17 outliers among 100 samples (17%)
variance is severely inflated by outliers
benchmarking format_performance_string_with_policy15
collecting 100 samples, 42 iterations each, in estimated 1898.4 μs
mean: 458.505 ns, lb 453.626 ns, ub 481.044 ns, ci 0.95
std dev: 45.5401 ns, lb 4.30147 ns, ub 108.045 ns, ci 0.95
found 4 outliers among 100 samples (4%)
variance is severely inflated by outliers
或在图表中:交互式链接