十一放假之前,看了一下 Nanolog 的论文,感觉思路非常赞,可惜 Nanolog 并不跨平台,而且为了性能和吞吐量,其日志输出并不直接可读。既然已经有了大体思路,接下来当然是自己撸一个啦!而且因为我也比较多 C 的库需要使用,所以就撸一个纯 C 的版本~
长假当中就断断续续写了一些,这几天在家的时间没事也写几段,今天大致到了较为满意的程度. 下面是在 Mac M1 2021 和 ThinkPad X1C 2019 上的 benchmark 结果 (测试程序可以直接在工程目录中找到: haclog gbenchmark),欢迎各位老板们使用和提意见
Mac M1 2021
Run on (8 X 24 MHz CPU s)
CPU Caches:
L1 Data 64 KiB
L1 Instruction 128 KiB
L2 Unified 4096 KiB (x8)
Load Average: 8.88, 4.53, 2.84
-----------------------------------------------------------------------------------------------------------
Benchmark Time CPU Iterations
-----------------------------------------------------------------------------------------------------------
ConstIterFixture/run/min_time:3.000/threads:1 66.3 ns 66.2 ns 60803739
ConstIterFixture/run/min_time:3.000/threads:2 34.0 ns 67.8 ns 58196532
ConstIterFixture/run/min_time:3.000/threads:4 24.7 ns 96.0 ns 46114032
ConstIterFixture/run/min_time:3.000/threads:7 30.0 ns 146 ns 25301248
ConstIterFixture/run/iterations:6000/repeats:5/threads:1 120 ns 120 ns 6000
ConstIterFixture/run/iterations:6000/repeats:5/threads:1 74.8 ns 74.8 ns 6000
ConstIterFixture/run/iterations:6000/repeats:5/threads:1 65.9 ns 66.0 ns 6000
ConstIterFixture/run/iterations:6000/repeats:5/threads:1 87.8 ns 87.8 ns 6000
ConstIterFixture/run/iterations:6000/repeats:5/threads:1 79.8 ns 80.0 ns 6000
ConstIterFixture/run/iterations:6000/repeats:5/threads:1_mean 85.7 ns 85.7 ns 5
ConstIterFixture/run/iterations:6000/repeats:5/threads:1_median 79.8 ns 80.0 ns 5
ConstIterFixture/run/iterations:6000/repeats:5/threads:1_stddev 20.8 ns 20.7 ns 5
ConstIterFixture/run/iterations:6000/repeats:5/threads:1_cv 24.29 % 24.19 % 5
ConstIterFixture/run/iterations:6000/repeats:5/threads:4 25.6 ns 102 ns 24000
ConstIterFixture/run/iterations:6000/repeats:5/threads:4 23.0 ns 91.8 ns 24000
ConstIterFixture/run/iterations:6000/repeats:5/threads:4 28.5 ns 114 ns 24000
ConstIterFixture/run/iterations:6000/repeats:5/threads:4 27.8 ns 111 ns 24000
ConstIterFixture/run/iterations:6000/repeats:5/threads:4 28.6 ns 114 ns 24000
ConstIterFixture/run/iterations:6000/repeats:5/threads:4_mean 26.7 ns 107 ns 5
ConstIterFixture/run/iterations:6000/repeats:5/threads:4_median 27.8 ns 111 ns 5
ConstIterFixture/run/iterations:6000/repeats:5/threads:4_stddev 2.42 ns 9.71 ns 5
ConstIterFixture/run/iterations:6000/repeats:5/threads:4_cv 9.05 % 9.09 % 5
ConstIterFixture/run/iterations:6000/repeats:5/threads:8 16.7 ns 132 ns 48000
ConstIterFixture/run/iterations:6000/repeats:5/threads:8 17.5 ns 130 ns 48000
ConstIterFixture/run/iterations:6000/repeats:5/threads:8 17.5 ns 135 ns 48000
ConstIterFixture/run/iterations:6000/repeats:5/threads:8 16.8 ns 134 ns 48000
ConstIterFixture/run/iterations:6000/repeats:5/threads:8 16.9 ns 133 ns 48000
ConstIterFixture/run/iterations:6000/repeats:5/threads:8_mean 17.1 ns 133 ns 5
ConstIterFixture/run/iterations:6000/repeats:5/threads:8_median 16.9 ns 133 ns 5
ConstIterFixture/run/iterations:6000/repeats:5/threads:8_stddev 0.396 ns 1.64 ns 5
ConstIterFixture/run/iterations:6000/repeats:5/threads:8_cv 2.32 % 1.24 % 5
ConstIterFixture/run/iterations:6000/repeats:5/threads:16 7.82 ns 125 ns 96000
ConstIterFixture/run/iterations:6000/repeats:5/threads:16 8.64 ns 136 ns 96000
ConstIterFixture/run/iterations:6000/repeats:5/threads:16 13.2 ns 204 ns 96000
ConstIterFixture/run/iterations:6000/repeats:5/threads:16 7.25 ns 114 ns 96000
ConstIterFixture/run/iterations:6000/repeats:5/threads:16 11.0 ns 169 ns 96000
ConstIterFixture/run/iterations:6000/repeats:5/threads:16_mean 9.57 ns 149 ns 5
ConstIterFixture/run/iterations:6000/repeats:5/threads:16_median 8.64 ns 136 ns 5
ConstIterFixture/run/iterations:6000/repeats:5/threads:16_stddev 2.47 ns 36.7 ns 5
ConstIterFixture/run/iterations:6000/repeats:5/threads:16_cv 25.83 % 24.56 % 5
Thinkpad X1C 2019
Run on (12 X 1780.93 MHz CPU s)
CPU Caches:
L1 Data 32 KiB (x6)
L1 Instruction 32 KiB (x6)
L2 Unified 256 KiB (x6)
L3 Unified 12288 KiB (x1)
Load Average: 0.09, 0.03, 0.08
-----------------------------------------------------------------------------------------------------------
Benchmark Time CPU Iterations
-----------------------------------------------------------------------------------------------------------
ConstIterFixture/run/min_time:3.000/threads:1 63.8 ns 63.7 ns 65480842
ConstIterFixture/run/min_time:3.000/threads:2 35.3 ns 70.6 ns 57795198
ConstIterFixture/run/min_time:3.000/threads:6 28.4 ns 170 ns 19480434
ConstIterFixture/run/min_time:3.000/threads:11 2491 ns 27350 ns 370425
ConstIterFixture/run/iterations:6000/repeats:5/threads:1 144 ns 144 ns 6000
ConstIterFixture/run/iterations:6000/repeats:5/threads:1 145 ns 144 ns 6000
ConstIterFixture/run/iterations:6000/repeats:5/threads:1 144 ns 144 ns 6000
ConstIterFixture/run/iterations:6000/repeats:5/threads:1 137 ns 136 ns 6000
ConstIterFixture/run/iterations:6000/repeats:5/threads:1 128 ns 128 ns 6000
ConstIterFixture/run/iterations:6000/repeats:5/threads:1_mean 140 ns 139 ns 5
ConstIterFixture/run/iterations:6000/repeats:5/threads:1_median 144 ns 144 ns 5
ConstIterFixture/run/iterations:6000/repeats:5/threads:1_stddev 7.14 ns 7.04 ns 5
ConstIterFixture/run/iterations:6000/repeats:5/threads:1_cv 5.11 % 5.06 % 5
ConstIterFixture/run/iterations:6000/repeats:5/threads:6 40.1 ns 241 ns 36000
ConstIterFixture/run/iterations:6000/repeats:5/threads:6 38.5 ns 231 ns 36000
ConstIterFixture/run/iterations:6000/repeats:5/threads:6 41.1 ns 246 ns 36000
ConstIterFixture/run/iterations:6000/repeats:5/threads:6 39.6 ns 238 ns 36000
ConstIterFixture/run/iterations:6000/repeats:5/threads:6 38.1 ns 228 ns 36000
ConstIterFixture/run/iterations:6000/repeats:5/threads:6_mean 39.5 ns 237 ns 5
ConstIterFixture/run/iterations:6000/repeats:5/threads:6_median 39.6 ns 238 ns 5
ConstIterFixture/run/iterations:6000/repeats:5/threads:6_stddev 1.20 ns 7.48 ns 5
ConstIterFixture/run/iterations:6000/repeats:5/threads:6_cv 3.03 % 3.16 % 5
ConstIterFixture/run/iterations:6000/repeats:5/threads:12 37.3 ns 446 ns 72000
ConstIterFixture/run/iterations:6000/repeats:5/threads:12 36.2 ns 434 ns 72000
ConstIterFixture/run/iterations:6000/repeats:5/threads:12 35.5 ns 426 ns 72000
ConstIterFixture/run/iterations:6000/repeats:5/threads:12 34.7 ns 416 ns 72000
ConstIterFixture/run/iterations:6000/repeats:5/threads:12 37.6 ns 450 ns 72000
ConstIterFixture/run/iterations:6000/repeats:5/threads:12_mean 36.3 ns 434 ns 5
ConstIterFixture/run/iterations:6000/repeats:5/threads:12_median 36.2 ns 434 ns 5
ConstIterFixture/run/iterations:6000/repeats:5/threads:12_stddev 1.21 ns 13.8 ns 5
ConstIterFixture/run/iterations:6000/repeats:5/threads:12_cv 3.34 % 3.19 % 5
ConstIterFixture/run/iterations:6000/repeats:5/threads:24 12.8 ns 307 ns 144000
ConstIterFixture/run/iterations:6000/repeats:5/threads:24 11.9 ns 286 ns 144000
ConstIterFixture/run/iterations:6000/repeats:5/threads:24 11.6 ns 277 ns 144000
ConstIterFixture/run/iterations:6000/repeats:5/threads:24 13.6 ns 326 ns 144000
ConstIterFixture/run/iterations:6000/repeats:5/threads:24 12.5 ns 300 ns 144000
ConstIterFixture/run/iterations:6000/repeats:5/threads:24_mean 12.5 ns 299 ns 5
ConstIterFixture/run/iterations:6000/repeats:5/threads:24_median 12.5 ns 300 ns 5
ConstIterFixture/run/iterations:6000/repeats:5/threads:24_stddev 0.783 ns 18.8 ns 5
ConstIterFixture/run/iterations:6000/repeats:5/threads:24_cv 6.27 % 6.28 % 5
threads, iterations, repeats, run