user_counters_tabular_test.cc 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557
  1. #undef NDEBUG
  2. #include "benchmark/benchmark.h"
  3. #include "output_test.h"
  4. // @todo: <jpmag> this checks the full output at once; the rule for
  5. // CounterSet1 was failing because it was not matching "^[-]+$".
  6. // @todo: <jpmag> check that the counters are vertically aligned.
  7. ADD_CASES(TC_ConsoleOut,
  8. {
  9. // keeping these lines long improves readability, so:
  10. // clang-format off
  11. {"^[-]+$", MR_Next},
  12. {"^Benchmark %s Time %s CPU %s Iterations %s Bar %s Bat %s Baz %s Foo %s Frob %s Lob$", MR_Next},
  13. {"^[-]+$", MR_Next},
  14. {"^BM_Counters_Tabular/repeats:2/threads:1 %console_report [ ]*%hrfloat [ ]*%hrfloat [ ]*%hrfloat [ ]*%hrfloat [ ]*%hrfloat [ ]*%hrfloat$", MR_Next},
  15. {"^BM_Counters_Tabular/repeats:2/threads:1 %console_report [ ]*%hrfloat [ ]*%hrfloat [ ]*%hrfloat [ ]*%hrfloat [ ]*%hrfloat [ ]*%hrfloat$", MR_Next},
  16. {"^BM_Counters_Tabular/repeats:2/threads:1_mean %console_report [ ]*%hrfloat [ ]*%hrfloat [ ]*%hrfloat [ ]*%hrfloat [ ]*%hrfloat [ ]*%hrfloat$", MR_Next},
  17. {"^BM_Counters_Tabular/repeats:2/threads:1_median %console_report [ ]*%hrfloat [ ]*%hrfloat [ ]*%hrfloat [ ]*%hrfloat [ ]*%hrfloat [ ]*%hrfloat$", MR_Next},
  18. {"^BM_Counters_Tabular/repeats:2/threads:1_stddev %console_report [ ]*%hrfloat [ ]*%hrfloat [ ]*%hrfloat [ ]*%hrfloat [ ]*%hrfloat [ ]*%hrfloat$", MR_Next},
  19. {"^BM_Counters_Tabular/repeats:2/threads:1_cv %console_percentage_report [ ]*%percentage[ ]*% [ ]*%percentage[ ]*% [ ]*%percentage[ ]*% [ ]*%percentage[ ]*% [ ]*%percentage[ ]*% [ ]*%percentage[ ]*%$", MR_Next},
  20. {"^BM_Counters_Tabular/repeats:2/threads:2 %console_report [ ]*%hrfloat [ ]*%hrfloat [ ]*%hrfloat [ ]*%hrfloat [ ]*%hrfloat [ ]*%hrfloat$", MR_Next},
  21. {"^BM_Counters_Tabular/repeats:2/threads:2 %console_report [ ]*%hrfloat [ ]*%hrfloat [ ]*%hrfloat [ ]*%hrfloat [ ]*%hrfloat [ ]*%hrfloat$", MR_Next},
  22. {"^BM_Counters_Tabular/repeats:2/threads:2_mean %console_report [ ]*%hrfloat [ ]*%hrfloat [ ]*%hrfloat [ ]*%hrfloat [ ]*%hrfloat [ ]*%hrfloat$", MR_Next},
  23. {"^BM_Counters_Tabular/repeats:2/threads:2_median %console_report [ ]*%hrfloat [ ]*%hrfloat [ ]*%hrfloat [ ]*%hrfloat [ ]*%hrfloat [ ]*%hrfloat$", MR_Next},
  24. {"^BM_Counters_Tabular/repeats:2/threads:2_stddev %console_report [ ]*%hrfloat [ ]*%hrfloat [ ]*%hrfloat [ ]*%hrfloat [ ]*%hrfloat [ ]*%hrfloat$", MR_Next},
  25. {"^BM_Counters_Tabular/repeats:2/threads:2_cv %console_percentage_report [ ]*%percentage[ ]*% [ ]*%percentage[ ]*% [ ]*%percentage[ ]*% [ ]*%percentage[ ]*% [ ]*%percentage[ ]*% [ ]*%percentage[ ]*%$", MR_Next},
  26. {"^BM_CounterRates_Tabular/threads:%int %console_report [ ]*%hrfloat/s [ ]*%hrfloat/s [ ]*%hrfloat/s [ ]*%hrfloat/s [ ]*%hrfloat/s [ ]*%hrfloat/s$", MR_Next},
  27. {"^BM_CounterRates_Tabular/threads:%int %console_report [ ]*%hrfloat/s [ ]*%hrfloat/s [ ]*%hrfloat/s [ ]*%hrfloat/s [ ]*%hrfloat/s [ ]*%hrfloat/s$", MR_Next},
  28. {"^BM_CounterRates_Tabular/threads:%int %console_report [ ]*%hrfloat/s [ ]*%hrfloat/s [ ]*%hrfloat/s [ ]*%hrfloat/s [ ]*%hrfloat/s [ ]*%hrfloat/s$", MR_Next},
  29. {"^BM_CounterRates_Tabular/threads:%int %console_report [ ]*%hrfloat/s [ ]*%hrfloat/s [ ]*%hrfloat/s [ ]*%hrfloat/s [ ]*%hrfloat/s [ ]*%hrfloat/s$", MR_Next},
  30. {"^BM_CounterRates_Tabular/threads:%int %console_report [ ]*%hrfloat/s [ ]*%hrfloat/s [ ]*%hrfloat/s [ ]*%hrfloat/s [ ]*%hrfloat/s [ ]*%hrfloat/s$", MR_Next},
  31. {"^[-]+$", MR_Next},
  32. {"^Benchmark %s Time %s CPU %s Iterations %s Bar %s Baz %s Foo$", MR_Next},
  33. {"^[-]+$", MR_Next},
  34. {"^BM_CounterSet0_Tabular/threads:%int %console_report [ ]*%hrfloat [ ]*%hrfloat [ ]*%hrfloat$", MR_Next},
  35. {"^BM_CounterSet0_Tabular/threads:%int %console_report [ ]*%hrfloat [ ]*%hrfloat [ ]*%hrfloat$", MR_Next},
  36. {"^BM_CounterSet0_Tabular/threads:%int %console_report [ ]*%hrfloat [ ]*%hrfloat [ ]*%hrfloat$", MR_Next},
  37. {"^BM_CounterSet0_Tabular/threads:%int %console_report [ ]*%hrfloat [ ]*%hrfloat [ ]*%hrfloat$", MR_Next},
  38. {"^BM_CounterSet0_Tabular/threads:%int %console_report [ ]*%hrfloat [ ]*%hrfloat [ ]*%hrfloat$", MR_Next},
  39. {"^BM_CounterSet1_Tabular/threads:%int %console_report [ ]*%hrfloat [ ]*%hrfloat [ ]*%hrfloat$", MR_Next},
  40. {"^BM_CounterSet1_Tabular/threads:%int %console_report [ ]*%hrfloat [ ]*%hrfloat [ ]*%hrfloat$", MR_Next},
  41. {"^BM_CounterSet1_Tabular/threads:%int %console_report [ ]*%hrfloat [ ]*%hrfloat [ ]*%hrfloat$", MR_Next},
  42. {"^BM_CounterSet1_Tabular/threads:%int %console_report [ ]*%hrfloat [ ]*%hrfloat [ ]*%hrfloat$", MR_Next},
  43. {"^BM_CounterSet1_Tabular/threads:%int %console_report [ ]*%hrfloat [ ]*%hrfloat [ ]*%hrfloat$", MR_Next},
  44. {"^[-]+$", MR_Next},
  45. {"^Benchmark %s Time %s CPU %s Iterations %s Bat %s Baz %s Foo$", MR_Next},
  46. {"^[-]+$", MR_Next},
  47. {"^BM_CounterSet2_Tabular/threads:%int %console_report [ ]*%hrfloat [ ]*%hrfloat [ ]*%hrfloat$", MR_Next},
  48. {"^BM_CounterSet2_Tabular/threads:%int %console_report [ ]*%hrfloat [ ]*%hrfloat [ ]*%hrfloat$", MR_Next},
  49. {"^BM_CounterSet2_Tabular/threads:%int %console_report [ ]*%hrfloat [ ]*%hrfloat [ ]*%hrfloat$", MR_Next},
  50. {"^BM_CounterSet2_Tabular/threads:%int %console_report [ ]*%hrfloat [ ]*%hrfloat [ ]*%hrfloat$", MR_Next},
  51. {"^BM_CounterSet2_Tabular/threads:%int %console_report [ ]*%hrfloat [ ]*%hrfloat [ ]*%hrfloat$"},
  52. // clang-format on
  53. });
  54. ADD_CASES(TC_CSVOut, {{"%csv_header,"
  55. "\"Bar\",\"Bat\",\"Baz\",\"Foo\",\"Frob\",\"Lob\""}});
  56. // ========================================================================= //
  57. // ------------------------- Tabular Counters Output ----------------------- //
  58. // ========================================================================= //
  59. void BM_Counters_Tabular(benchmark::State& state) {
  60. for (auto _ : state) {
  61. }
  62. namespace bm = benchmark;
  63. state.counters.insert({
  64. {"Foo", {1, bm::Counter::kAvgThreads}},
  65. {"Bar", {2, bm::Counter::kAvgThreads}},
  66. {"Baz", {4, bm::Counter::kAvgThreads}},
  67. {"Bat", {8, bm::Counter::kAvgThreads}},
  68. {"Frob", {16, bm::Counter::kAvgThreads}},
  69. {"Lob", {32, bm::Counter::kAvgThreads}},
  70. });
  71. }
  72. BENCHMARK(BM_Counters_Tabular)->ThreadRange(1, 2)->Repetitions(2);
  73. ADD_CASES(TC_JSONOut,
  74. {{"\"name\": \"BM_Counters_Tabular/repeats:2/threads:1\",$"},
  75. {"\"family_index\": 0,$", MR_Next},
  76. {"\"per_family_instance_index\": 0,$", MR_Next},
  77. {"\"run_name\": \"BM_Counters_Tabular/repeats:2/threads:1\",$",
  78. MR_Next},
  79. {"\"run_type\": \"iteration\",$", MR_Next},
  80. {"\"repetitions\": 2,$", MR_Next},
  81. {"\"repetition_index\": 0,$", MR_Next},
  82. {"\"threads\": 1,$", MR_Next},
  83. {"\"iterations\": %int,$", MR_Next},
  84. {"\"real_time\": %float,$", MR_Next},
  85. {"\"cpu_time\": %float,$", MR_Next},
  86. {"\"time_unit\": \"ns\",$", MR_Next},
  87. {"\"Bar\": %float,$", MR_Next},
  88. {"\"Bat\": %float,$", MR_Next},
  89. {"\"Baz\": %float,$", MR_Next},
  90. {"\"Foo\": %float,$", MR_Next},
  91. {"\"Frob\": %float,$", MR_Next},
  92. {"\"Lob\": %float$", MR_Next},
  93. {"}", MR_Next}});
  94. ADD_CASES(TC_JSONOut,
  95. {{"\"name\": \"BM_Counters_Tabular/repeats:2/threads:1\",$"},
  96. {"\"family_index\": 0,$", MR_Next},
  97. {"\"per_family_instance_index\": 0,$", MR_Next},
  98. {"\"run_name\": \"BM_Counters_Tabular/repeats:2/threads:1\",$",
  99. MR_Next},
  100. {"\"run_type\": \"iteration\",$", MR_Next},
  101. {"\"repetitions\": 2,$", MR_Next},
  102. {"\"repetition_index\": 1,$", MR_Next},
  103. {"\"threads\": 1,$", MR_Next},
  104. {"\"iterations\": %int,$", MR_Next},
  105. {"\"real_time\": %float,$", MR_Next},
  106. {"\"cpu_time\": %float,$", MR_Next},
  107. {"\"time_unit\": \"ns\",$", MR_Next},
  108. {"\"Bar\": %float,$", MR_Next},
  109. {"\"Bat\": %float,$", MR_Next},
  110. {"\"Baz\": %float,$", MR_Next},
  111. {"\"Foo\": %float,$", MR_Next},
  112. {"\"Frob\": %float,$", MR_Next},
  113. {"\"Lob\": %float$", MR_Next},
  114. {"}", MR_Next}});
  115. ADD_CASES(TC_JSONOut,
  116. {{"\"name\": \"BM_Counters_Tabular/repeats:2/threads:1_mean\",$"},
  117. {"\"family_index\": 0,$", MR_Next},
  118. {"\"per_family_instance_index\": 0,$", MR_Next},
  119. {"\"run_name\": \"BM_Counters_Tabular/repeats:2/threads:1\",$",
  120. MR_Next},
  121. {"\"run_type\": \"aggregate\",$", MR_Next},
  122. {"\"repetitions\": 2,$", MR_Next},
  123. {"\"threads\": 1,$", MR_Next},
  124. {"\"aggregate_name\": \"mean\",$", MR_Next},
  125. {"\"aggregate_unit\": \"time\",$", MR_Next},
  126. {"\"iterations\": %int,$", MR_Next},
  127. {"\"real_time\": %float,$", MR_Next},
  128. {"\"cpu_time\": %float,$", MR_Next},
  129. {"\"time_unit\": \"ns\",$", MR_Next},
  130. {"\"Bar\": %float,$", MR_Next},
  131. {"\"Bat\": %float,$", MR_Next},
  132. {"\"Baz\": %float,$", MR_Next},
  133. {"\"Foo\": %float,$", MR_Next},
  134. {"\"Frob\": %float,$", MR_Next},
  135. {"\"Lob\": %float$", MR_Next},
  136. {"}", MR_Next}});
  137. ADD_CASES(TC_JSONOut,
  138. {{"\"name\": \"BM_Counters_Tabular/repeats:2/threads:1_median\",$"},
  139. {"\"family_index\": 0,$", MR_Next},
  140. {"\"per_family_instance_index\": 0,$", MR_Next},
  141. {"\"run_name\": \"BM_Counters_Tabular/repeats:2/threads:1\",$",
  142. MR_Next},
  143. {"\"run_type\": \"aggregate\",$", MR_Next},
  144. {"\"repetitions\": 2,$", MR_Next},
  145. {"\"threads\": 1,$", MR_Next},
  146. {"\"aggregate_name\": \"median\",$", MR_Next},
  147. {"\"aggregate_unit\": \"time\",$", MR_Next},
  148. {"\"iterations\": %int,$", MR_Next},
  149. {"\"real_time\": %float,$", MR_Next},
  150. {"\"cpu_time\": %float,$", MR_Next},
  151. {"\"time_unit\": \"ns\",$", MR_Next},
  152. {"\"Bar\": %float,$", MR_Next},
  153. {"\"Bat\": %float,$", MR_Next},
  154. {"\"Baz\": %float,$", MR_Next},
  155. {"\"Foo\": %float,$", MR_Next},
  156. {"\"Frob\": %float,$", MR_Next},
  157. {"\"Lob\": %float$", MR_Next},
  158. {"}", MR_Next}});
  159. ADD_CASES(TC_JSONOut,
  160. {{"\"name\": \"BM_Counters_Tabular/repeats:2/threads:1_stddev\",$"},
  161. {"\"family_index\": 0,$", MR_Next},
  162. {"\"per_family_instance_index\": 0,$", MR_Next},
  163. {"\"run_name\": \"BM_Counters_Tabular/repeats:2/threads:1\",$",
  164. MR_Next},
  165. {"\"run_type\": \"aggregate\",$", MR_Next},
  166. {"\"repetitions\": 2,$", MR_Next},
  167. {"\"threads\": 1,$", MR_Next},
  168. {"\"aggregate_name\": \"stddev\",$", MR_Next},
  169. {"\"aggregate_unit\": \"time\",$", MR_Next},
  170. {"\"iterations\": %int,$", MR_Next},
  171. {"\"real_time\": %float,$", MR_Next},
  172. {"\"cpu_time\": %float,$", MR_Next},
  173. {"\"time_unit\": \"ns\",$", MR_Next},
  174. {"\"Bar\": %float,$", MR_Next},
  175. {"\"Bat\": %float,$", MR_Next},
  176. {"\"Baz\": %float,$", MR_Next},
  177. {"\"Foo\": %float,$", MR_Next},
  178. {"\"Frob\": %float,$", MR_Next},
  179. {"\"Lob\": %float$", MR_Next},
  180. {"}", MR_Next}});
  181. ADD_CASES(TC_JSONOut,
  182. {{"\"name\": \"BM_Counters_Tabular/repeats:2/threads:1_cv\",$"},
  183. {"\"family_index\": 0,$", MR_Next},
  184. {"\"per_family_instance_index\": 0,$", MR_Next},
  185. {"\"run_name\": \"BM_Counters_Tabular/repeats:2/threads:1\",$",
  186. MR_Next},
  187. {"\"run_type\": \"aggregate\",$", MR_Next},
  188. {"\"repetitions\": 2,$", MR_Next},
  189. {"\"threads\": 1,$", MR_Next},
  190. {"\"aggregate_name\": \"cv\",$", MR_Next},
  191. {"\"aggregate_unit\": \"percentage\",$", MR_Next},
  192. {"\"iterations\": %int,$", MR_Next},
  193. {"\"real_time\": %float,$", MR_Next},
  194. {"\"cpu_time\": %float,$", MR_Next},
  195. {"\"time_unit\": \"ns\",$", MR_Next},
  196. {"\"Bar\": %float,$", MR_Next},
  197. {"\"Bat\": %float,$", MR_Next},
  198. {"\"Baz\": %float,$", MR_Next},
  199. {"\"Foo\": %float,$", MR_Next},
  200. {"\"Frob\": %float,$", MR_Next},
  201. {"\"Lob\": %float$", MR_Next},
  202. {"}", MR_Next}});
  203. ADD_CASES(TC_JSONOut,
  204. {{"\"name\": \"BM_Counters_Tabular/repeats:2/threads:2\",$"},
  205. {"\"family_index\": 0,$", MR_Next},
  206. {"\"per_family_instance_index\": 1,$", MR_Next},
  207. {"\"run_name\": \"BM_Counters_Tabular/repeats:2/threads:2\",$",
  208. MR_Next},
  209. {"\"run_type\": \"iteration\",$", MR_Next},
  210. {"\"repetitions\": 2,$", MR_Next},
  211. {"\"repetition_index\": 0,$", MR_Next},
  212. {"\"threads\": 2,$", MR_Next},
  213. {"\"iterations\": %int,$", MR_Next},
  214. {"\"real_time\": %float,$", MR_Next},
  215. {"\"cpu_time\": %float,$", MR_Next},
  216. {"\"time_unit\": \"ns\",$", MR_Next},
  217. {"\"Bar\": %float,$", MR_Next},
  218. {"\"Bat\": %float,$", MR_Next},
  219. {"\"Baz\": %float,$", MR_Next},
  220. {"\"Foo\": %float,$", MR_Next},
  221. {"\"Frob\": %float,$", MR_Next},
  222. {"\"Lob\": %float$", MR_Next},
  223. {"}", MR_Next}});
  224. ADD_CASES(TC_JSONOut,
  225. {{"\"name\": \"BM_Counters_Tabular/repeats:2/threads:2\",$"},
  226. {"\"family_index\": 0,$", MR_Next},
  227. {"\"per_family_instance_index\": 1,$", MR_Next},
  228. {"\"run_name\": \"BM_Counters_Tabular/repeats:2/threads:2\",$",
  229. MR_Next},
  230. {"\"run_type\": \"iteration\",$", MR_Next},
  231. {"\"repetitions\": 2,$", MR_Next},
  232. {"\"repetition_index\": 1,$", MR_Next},
  233. {"\"threads\": 2,$", MR_Next},
  234. {"\"iterations\": %int,$", MR_Next},
  235. {"\"real_time\": %float,$", MR_Next},
  236. {"\"cpu_time\": %float,$", MR_Next},
  237. {"\"time_unit\": \"ns\",$", MR_Next},
  238. {"\"Bar\": %float,$", MR_Next},
  239. {"\"Bat\": %float,$", MR_Next},
  240. {"\"Baz\": %float,$", MR_Next},
  241. {"\"Foo\": %float,$", MR_Next},
  242. {"\"Frob\": %float,$", MR_Next},
  243. {"\"Lob\": %float$", MR_Next},
  244. {"}", MR_Next}});
  245. ADD_CASES(TC_JSONOut,
  246. {{"\"name\": \"BM_Counters_Tabular/repeats:2/threads:2_median\",$"},
  247. {"\"family_index\": 0,$", MR_Next},
  248. {"\"per_family_instance_index\": 1,$", MR_Next},
  249. {"\"run_name\": \"BM_Counters_Tabular/repeats:2/threads:2\",$",
  250. MR_Next},
  251. {"\"run_type\": \"aggregate\",$", MR_Next},
  252. {"\"repetitions\": 2,$", MR_Next},
  253. {"\"threads\": 2,$", MR_Next},
  254. {"\"aggregate_name\": \"median\",$", MR_Next},
  255. {"\"aggregate_unit\": \"time\",$", MR_Next},
  256. {"\"iterations\": %int,$", MR_Next},
  257. {"\"real_time\": %float,$", MR_Next},
  258. {"\"cpu_time\": %float,$", MR_Next},
  259. {"\"time_unit\": \"ns\",$", MR_Next},
  260. {"\"Bar\": %float,$", MR_Next},
  261. {"\"Bat\": %float,$", MR_Next},
  262. {"\"Baz\": %float,$", MR_Next},
  263. {"\"Foo\": %float,$", MR_Next},
  264. {"\"Frob\": %float,$", MR_Next},
  265. {"\"Lob\": %float$", MR_Next},
  266. {"}", MR_Next}});
  267. ADD_CASES(TC_JSONOut,
  268. {{"\"name\": \"BM_Counters_Tabular/repeats:2/threads:2_stddev\",$"},
  269. {"\"family_index\": 0,$", MR_Next},
  270. {"\"per_family_instance_index\": 1,$", MR_Next},
  271. {"\"run_name\": \"BM_Counters_Tabular/repeats:2/threads:2\",$",
  272. MR_Next},
  273. {"\"run_type\": \"aggregate\",$", MR_Next},
  274. {"\"repetitions\": 2,$", MR_Next},
  275. {"\"threads\": 2,$", MR_Next},
  276. {"\"aggregate_name\": \"stddev\",$", MR_Next},
  277. {"\"aggregate_unit\": \"time\",$", MR_Next},
  278. {"\"iterations\": %int,$", MR_Next},
  279. {"\"real_time\": %float,$", MR_Next},
  280. {"\"cpu_time\": %float,$", MR_Next},
  281. {"\"time_unit\": \"ns\",$", MR_Next},
  282. {"\"Bar\": %float,$", MR_Next},
  283. {"\"Bat\": %float,$", MR_Next},
  284. {"\"Baz\": %float,$", MR_Next},
  285. {"\"Foo\": %float,$", MR_Next},
  286. {"\"Frob\": %float,$", MR_Next},
  287. {"\"Lob\": %float$", MR_Next},
  288. {"}", MR_Next}});
  289. ADD_CASES(TC_JSONOut,
  290. {{"\"name\": \"BM_Counters_Tabular/repeats:2/threads:2_cv\",$"},
  291. {"\"family_index\": 0,$", MR_Next},
  292. {"\"per_family_instance_index\": 1,$", MR_Next},
  293. {"\"run_name\": \"BM_Counters_Tabular/repeats:2/threads:2\",$",
  294. MR_Next},
  295. {"\"run_type\": \"aggregate\",$", MR_Next},
  296. {"\"repetitions\": 2,$", MR_Next},
  297. {"\"threads\": 2,$", MR_Next},
  298. {"\"aggregate_name\": \"cv\",$", MR_Next},
  299. {"\"aggregate_unit\": \"percentage\",$", MR_Next},
  300. {"\"iterations\": %int,$", MR_Next},
  301. {"\"real_time\": %float,$", MR_Next},
  302. {"\"cpu_time\": %float,$", MR_Next},
  303. {"\"time_unit\": \"ns\",$", MR_Next},
  304. {"\"Bar\": %float,$", MR_Next},
  305. {"\"Bat\": %float,$", MR_Next},
  306. {"\"Baz\": %float,$", MR_Next},
  307. {"\"Foo\": %float,$", MR_Next},
  308. {"\"Frob\": %float,$", MR_Next},
  309. {"\"Lob\": %float$", MR_Next},
  310. {"}", MR_Next}});
  311. ADD_CASES(TC_CSVOut,
  312. {{"^\"BM_Counters_Tabular/repeats:2/threads:1\",%csv_report,"
  313. "%float,%float,%float,%float,%float,%float$"}});
  314. ADD_CASES(TC_CSVOut,
  315. {{"^\"BM_Counters_Tabular/repeats:2/threads:1\",%csv_report,"
  316. "%float,%float,%float,%float,%float,%float$"}});
  317. ADD_CASES(TC_CSVOut,
  318. {{"^\"BM_Counters_Tabular/repeats:2/threads:1_mean\",%csv_report,"
  319. "%float,%float,%float,%float,%float,%float$"}});
  320. ADD_CASES(TC_CSVOut,
  321. {{"^\"BM_Counters_Tabular/repeats:2/threads:1_median\",%csv_report,"
  322. "%float,%float,%float,%float,%float,%float$"}});
  323. ADD_CASES(TC_CSVOut,
  324. {{"^\"BM_Counters_Tabular/repeats:2/threads:1_stddev\",%csv_report,"
  325. "%float,%float,%float,%float,%float,%float$"}});
  326. ADD_CASES(TC_CSVOut,
  327. {{"^\"BM_Counters_Tabular/repeats:2/threads:1_cv\",%csv_report,"
  328. "%float,%float,%float,%float,%float,%float$"}});
  329. ADD_CASES(TC_CSVOut,
  330. {{"^\"BM_Counters_Tabular/repeats:2/threads:2\",%csv_report,"
  331. "%float,%float,%float,%float,%float,%float$"}});
  332. ADD_CASES(TC_CSVOut,
  333. {{"^\"BM_Counters_Tabular/repeats:2/threads:2\",%csv_report,"
  334. "%float,%float,%float,%float,%float,%float$"}});
  335. ADD_CASES(TC_CSVOut,
  336. {{"^\"BM_Counters_Tabular/repeats:2/threads:2_mean\",%csv_report,"
  337. "%float,%float,%float,%float,%float,%float$"}});
  338. ADD_CASES(TC_CSVOut,
  339. {{"^\"BM_Counters_Tabular/repeats:2/threads:2_median\",%csv_report,"
  340. "%float,%float,%float,%float,%float,%float$"}});
  341. ADD_CASES(TC_CSVOut,
  342. {{"^\"BM_Counters_Tabular/repeats:2/threads:2_stddev\",%csv_report,"
  343. "%float,%float,%float,%float,%float,%float$"}});
  344. ADD_CASES(TC_CSVOut,
  345. {{"^\"BM_Counters_Tabular/repeats:2/threads:2_cv\",%csv_report,"
  346. "%float,%float,%float,%float,%float,%float$"}});
  347. // VS2013 does not allow this function to be passed as a lambda argument
  348. // to CHECK_BENCHMARK_RESULTS()
  349. void CheckTabular(Results const& e) {
  350. CHECK_COUNTER_VALUE(e, int, "Foo", EQ, 1);
  351. CHECK_COUNTER_VALUE(e, int, "Bar", EQ, 2);
  352. CHECK_COUNTER_VALUE(e, int, "Baz", EQ, 4);
  353. CHECK_COUNTER_VALUE(e, int, "Bat", EQ, 8);
  354. CHECK_COUNTER_VALUE(e, int, "Frob", EQ, 16);
  355. CHECK_COUNTER_VALUE(e, int, "Lob", EQ, 32);
  356. }
  357. CHECK_BENCHMARK_RESULTS("BM_Counters_Tabular/repeats:2/threads:1$",
  358. &CheckTabular);
  359. CHECK_BENCHMARK_RESULTS("BM_Counters_Tabular/repeats:2/threads:2$",
  360. &CheckTabular);
  361. // ========================================================================= //
  362. // -------------------- Tabular+Rate Counters Output ----------------------- //
  363. // ========================================================================= //
  364. void BM_CounterRates_Tabular(benchmark::State& state) {
  365. for (auto _ : state) {
  366. // This test requires a non-zero CPU time to avoid divide-by-zero
  367. benchmark::DoNotOptimize(state.iterations());
  368. }
  369. namespace bm = benchmark;
  370. state.counters.insert({
  371. {"Foo", {1, bm::Counter::kAvgThreadsRate}},
  372. {"Bar", {2, bm::Counter::kAvgThreadsRate}},
  373. {"Baz", {4, bm::Counter::kAvgThreadsRate}},
  374. {"Bat", {8, bm::Counter::kAvgThreadsRate}},
  375. {"Frob", {16, bm::Counter::kAvgThreadsRate}},
  376. {"Lob", {32, bm::Counter::kAvgThreadsRate}},
  377. });
  378. }
  379. BENCHMARK(BM_CounterRates_Tabular)->ThreadRange(1, 16);
  380. ADD_CASES(TC_JSONOut,
  381. {{"\"name\": \"BM_CounterRates_Tabular/threads:%int\",$"},
  382. {"\"family_index\": 1,$", MR_Next},
  383. {"\"per_family_instance_index\": 0,$", MR_Next},
  384. {"\"run_name\": \"BM_CounterRates_Tabular/threads:%int\",$",
  385. MR_Next},
  386. {"\"run_type\": \"iteration\",$", MR_Next},
  387. {"\"repetitions\": 1,$", MR_Next},
  388. {"\"repetition_index\": 0,$", MR_Next},
  389. {"\"threads\": 1,$", MR_Next},
  390. {"\"iterations\": %int,$", MR_Next},
  391. {"\"real_time\": %float,$", MR_Next},
  392. {"\"cpu_time\": %float,$", MR_Next},
  393. {"\"time_unit\": \"ns\",$", MR_Next},
  394. {"\"Bar\": %float,$", MR_Next},
  395. {"\"Bat\": %float,$", MR_Next},
  396. {"\"Baz\": %float,$", MR_Next},
  397. {"\"Foo\": %float,$", MR_Next},
  398. {"\"Frob\": %float,$", MR_Next},
  399. {"\"Lob\": %float$", MR_Next},
  400. {"}", MR_Next}});
  401. ADD_CASES(TC_CSVOut, {{"^\"BM_CounterRates_Tabular/threads:%int\",%csv_report,"
  402. "%float,%float,%float,%float,%float,%float$"}});
  403. // VS2013 does not allow this function to be passed as a lambda argument
  404. // to CHECK_BENCHMARK_RESULTS()
  405. void CheckTabularRate(Results const& e) {
  406. double t = e.DurationCPUTime();
  407. CHECK_FLOAT_COUNTER_VALUE(e, "Foo", EQ, 1. / t, 0.001);
  408. CHECK_FLOAT_COUNTER_VALUE(e, "Bar", EQ, 2. / t, 0.001);
  409. CHECK_FLOAT_COUNTER_VALUE(e, "Baz", EQ, 4. / t, 0.001);
  410. CHECK_FLOAT_COUNTER_VALUE(e, "Bat", EQ, 8. / t, 0.001);
  411. CHECK_FLOAT_COUNTER_VALUE(e, "Frob", EQ, 16. / t, 0.001);
  412. CHECK_FLOAT_COUNTER_VALUE(e, "Lob", EQ, 32. / t, 0.001);
  413. }
  414. CHECK_BENCHMARK_RESULTS("BM_CounterRates_Tabular/threads:%int",
  415. &CheckTabularRate);
  416. // ========================================================================= //
  417. // ------------------------- Tabular Counters Output ----------------------- //
  418. // ========================================================================= //
  419. // set only some of the counters
  420. void BM_CounterSet0_Tabular(benchmark::State& state) {
  421. for (auto _ : state) {
  422. }
  423. namespace bm = benchmark;
  424. state.counters.insert({
  425. {"Foo", {10, bm::Counter::kAvgThreads}},
  426. {"Bar", {20, bm::Counter::kAvgThreads}},
  427. {"Baz", {40, bm::Counter::kAvgThreads}},
  428. });
  429. }
  430. BENCHMARK(BM_CounterSet0_Tabular)->ThreadRange(1, 16);
  431. ADD_CASES(TC_JSONOut,
  432. {{"\"name\": \"BM_CounterSet0_Tabular/threads:%int\",$"},
  433. {"\"family_index\": 2,$", MR_Next},
  434. {"\"per_family_instance_index\": 0,$", MR_Next},
  435. {"\"run_name\": \"BM_CounterSet0_Tabular/threads:%int\",$", MR_Next},
  436. {"\"run_type\": \"iteration\",$", MR_Next},
  437. {"\"repetitions\": 1,$", MR_Next},
  438. {"\"repetition_index\": 0,$", MR_Next},
  439. {"\"threads\": 1,$", MR_Next},
  440. {"\"iterations\": %int,$", MR_Next},
  441. {"\"real_time\": %float,$", MR_Next},
  442. {"\"cpu_time\": %float,$", MR_Next},
  443. {"\"time_unit\": \"ns\",$", MR_Next},
  444. {"\"Bar\": %float,$", MR_Next},
  445. {"\"Baz\": %float,$", MR_Next},
  446. {"\"Foo\": %float$", MR_Next},
  447. {"}", MR_Next}});
  448. ADD_CASES(TC_CSVOut, {{"^\"BM_CounterSet0_Tabular/threads:%int\",%csv_report,"
  449. "%float,,%float,%float,,"}});
  450. // VS2013 does not allow this function to be passed as a lambda argument
  451. // to CHECK_BENCHMARK_RESULTS()
  452. void CheckSet0(Results const& e) {
  453. CHECK_COUNTER_VALUE(e, int, "Foo", EQ, 10);
  454. CHECK_COUNTER_VALUE(e, int, "Bar", EQ, 20);
  455. CHECK_COUNTER_VALUE(e, int, "Baz", EQ, 40);
  456. }
  457. CHECK_BENCHMARK_RESULTS("BM_CounterSet0_Tabular", &CheckSet0);
  458. // again.
  459. void BM_CounterSet1_Tabular(benchmark::State& state) {
  460. for (auto _ : state) {
  461. }
  462. namespace bm = benchmark;
  463. state.counters.insert({
  464. {"Foo", {15, bm::Counter::kAvgThreads}},
  465. {"Bar", {25, bm::Counter::kAvgThreads}},
  466. {"Baz", {45, bm::Counter::kAvgThreads}},
  467. });
  468. }
  469. BENCHMARK(BM_CounterSet1_Tabular)->ThreadRange(1, 16);
  470. ADD_CASES(TC_JSONOut,
  471. {{"\"name\": \"BM_CounterSet1_Tabular/threads:%int\",$"},
  472. {"\"family_index\": 3,$", MR_Next},
  473. {"\"per_family_instance_index\": 0,$", MR_Next},
  474. {"\"run_name\": \"BM_CounterSet1_Tabular/threads:%int\",$", MR_Next},
  475. {"\"run_type\": \"iteration\",$", MR_Next},
  476. {"\"repetitions\": 1,$", MR_Next},
  477. {"\"repetition_index\": 0,$", MR_Next},
  478. {"\"threads\": 1,$", MR_Next},
  479. {"\"iterations\": %int,$", MR_Next},
  480. {"\"real_time\": %float,$", MR_Next},
  481. {"\"cpu_time\": %float,$", MR_Next},
  482. {"\"time_unit\": \"ns\",$", MR_Next},
  483. {"\"Bar\": %float,$", MR_Next},
  484. {"\"Baz\": %float,$", MR_Next},
  485. {"\"Foo\": %float$", MR_Next},
  486. {"}", MR_Next}});
  487. ADD_CASES(TC_CSVOut, {{"^\"BM_CounterSet1_Tabular/threads:%int\",%csv_report,"
  488. "%float,,%float,%float,,"}});
  489. // VS2013 does not allow this function to be passed as a lambda argument
  490. // to CHECK_BENCHMARK_RESULTS()
  491. void CheckSet1(Results const& e) {
  492. CHECK_COUNTER_VALUE(e, int, "Foo", EQ, 15);
  493. CHECK_COUNTER_VALUE(e, int, "Bar", EQ, 25);
  494. CHECK_COUNTER_VALUE(e, int, "Baz", EQ, 45);
  495. }
  496. CHECK_BENCHMARK_RESULTS("BM_CounterSet1_Tabular/threads:%int", &CheckSet1);
  497. // ========================================================================= //
  498. // ------------------------- Tabular Counters Output ----------------------- //
  499. // ========================================================================= //
  500. // set only some of the counters, different set now.
  501. void BM_CounterSet2_Tabular(benchmark::State& state) {
  502. for (auto _ : state) {
  503. }
  504. namespace bm = benchmark;
  505. state.counters.insert({
  506. {"Foo", {10, bm::Counter::kAvgThreads}},
  507. {"Bat", {30, bm::Counter::kAvgThreads}},
  508. {"Baz", {40, bm::Counter::kAvgThreads}},
  509. });
  510. }
  511. BENCHMARK(BM_CounterSet2_Tabular)->ThreadRange(1, 16);
  512. ADD_CASES(TC_JSONOut,
  513. {{"\"name\": \"BM_CounterSet2_Tabular/threads:%int\",$"},
  514. {"\"family_index\": 4,$", MR_Next},
  515. {"\"per_family_instance_index\": 0,$", MR_Next},
  516. {"\"run_name\": \"BM_CounterSet2_Tabular/threads:%int\",$", MR_Next},
  517. {"\"run_type\": \"iteration\",$", MR_Next},
  518. {"\"repetitions\": 1,$", MR_Next},
  519. {"\"repetition_index\": 0,$", MR_Next},
  520. {"\"threads\": 1,$", MR_Next},
  521. {"\"iterations\": %int,$", MR_Next},
  522. {"\"real_time\": %float,$", MR_Next},
  523. {"\"cpu_time\": %float,$", MR_Next},
  524. {"\"time_unit\": \"ns\",$", MR_Next},
  525. {"\"Bat\": %float,$", MR_Next},
  526. {"\"Baz\": %float,$", MR_Next},
  527. {"\"Foo\": %float$", MR_Next},
  528. {"}", MR_Next}});
  529. ADD_CASES(TC_CSVOut, {{"^\"BM_CounterSet2_Tabular/threads:%int\",%csv_report,"
  530. ",%float,%float,%float,,"}});
  531. // VS2013 does not allow this function to be passed as a lambda argument
  532. // to CHECK_BENCHMARK_RESULTS()
  533. void CheckSet2(Results const& e) {
  534. CHECK_COUNTER_VALUE(e, int, "Foo", EQ, 10);
  535. CHECK_COUNTER_VALUE(e, int, "Bat", EQ, 30);
  536. CHECK_COUNTER_VALUE(e, int, "Baz", EQ, 40);
  537. }
  538. CHECK_BENCHMARK_RESULTS("BM_CounterSet2_Tabular", &CheckSet2);
  539. // ========================================================================= //
  540. // --------------------------- TEST CASES END ------------------------------ //
  541. // ========================================================================= //
  542. int main(int argc, char* argv[]) { RunOutputTests(argc, argv); }