1 
2 #undef NDEBUG
3 
4 #include "benchmark/benchmark.h"
5 #include "output_test.h"
6 
7 // ========================================================================= //
8 // ------------------------ Thousands Customisation ------------------------ //
9 // ========================================================================= //
10 
BM_Counters_Thousands(benchmark::State & state)11 void BM_Counters_Thousands(benchmark::State& state) {
12   for (auto _ : state) {
13   }
14   namespace bm = benchmark;
15   state.counters.insert({
16       {"t0_1000000DefaultBase",
17        bm::Counter(1000 * 1000, bm::Counter::kDefaults)},
18       {"t1_1000000Base1000", bm::Counter(1000 * 1000, bm::Counter::kDefaults,
19                                          benchmark::Counter::OneK::kIs1000)},
20       {"t2_1000000Base1024", bm::Counter(1000 * 1000, bm::Counter::kDefaults,
21                                          benchmark::Counter::OneK::kIs1024)},
22       {"t3_1048576Base1000", bm::Counter(1024 * 1024, bm::Counter::kDefaults,
23                                          benchmark::Counter::OneK::kIs1000)},
24       {"t4_1048576Base1024", bm::Counter(1024 * 1024, bm::Counter::kDefaults,
25                                          benchmark::Counter::OneK::kIs1024)},
26   });
27 }
28 BENCHMARK(BM_Counters_Thousands)->Repetitions(2);
29 ADD_CASES(
30     TC_ConsoleOut,
31     {
32         {"^BM_Counters_Thousands/repeats:2 %console_report "
33          "t0_1000000DefaultBase=1000k "
34          "t1_1000000Base1000=1000k t2_1000000Base1024=976.56[23]k "
35          "t3_1048576Base1000=1048.58k t4_1048576Base1024=1024k$"},
36         {"^BM_Counters_Thousands/repeats:2 %console_report "
37          "t0_1000000DefaultBase=1000k "
38          "t1_1000000Base1000=1000k t2_1000000Base1024=976.56[23]k "
39          "t3_1048576Base1000=1048.58k t4_1048576Base1024=1024k$"},
40         {"^BM_Counters_Thousands/repeats:2_mean %console_report "
41          "t0_1000000DefaultBase=1000k t1_1000000Base1000=1000k "
42          "t2_1000000Base1024=976.56[23]k t3_1048576Base1000=1048.58k "
43          "t4_1048576Base1024=1024k$"},
44         {"^BM_Counters_Thousands/repeats:2_median %console_report "
45          "t0_1000000DefaultBase=1000k t1_1000000Base1000=1000k "
46          "t2_1000000Base1024=976.56[23]k t3_1048576Base1000=1048.58k "
47          "t4_1048576Base1024=1024k$"},
48         {"^BM_Counters_Thousands/repeats:2_stddev %console_time_only_report [ "
49          "]*2 t0_1000000DefaultBase=0 t1_1000000Base1000=0 "
50          "t2_1000000Base1024=0 t3_1048576Base1000=0 t4_1048576Base1024=0$"},
51     });
52 ADD_CASES(TC_JSONOut,
53           {{"\"name\": \"BM_Counters_Thousands/repeats:2\",$"},
54            {"\"run_name\": \"BM_Counters_Thousands/repeats:2\",$", MR_Next},
55            {"\"run_type\": \"iteration\",$", MR_Next},
56            {"\"repetitions\": 2,$", MR_Next},
57            {"\"repetition_index\": 0,$", MR_Next},
58            {"\"threads\": 1,$", MR_Next},
59            {"\"iterations\": %int,$", MR_Next},
60            {"\"real_time\": %float,$", MR_Next},
61            {"\"cpu_time\": %float,$", MR_Next},
62            {"\"time_unit\": \"ns\",$", MR_Next},
63            {"\"t0_1000000DefaultBase\": 1\\.(0)*e\\+(0)*6,$", MR_Next},
64            {"\"t1_1000000Base1000\": 1\\.(0)*e\\+(0)*6,$", MR_Next},
65            {"\"t2_1000000Base1024\": 1\\.(0)*e\\+(0)*6,$", MR_Next},
66            {"\"t3_1048576Base1000\": 1\\.048576(0)*e\\+(0)*6,$", MR_Next},
67            {"\"t4_1048576Base1024\": 1\\.048576(0)*e\\+(0)*6$", MR_Next},
68            {"}", MR_Next}});
69 ADD_CASES(TC_JSONOut,
70           {{"\"name\": \"BM_Counters_Thousands/repeats:2\",$"},
71            {"\"run_name\": \"BM_Counters_Thousands/repeats:2\",$", MR_Next},
72            {"\"run_type\": \"iteration\",$", MR_Next},
73            {"\"repetitions\": 2,$", MR_Next},
74            {"\"repetition_index\": 1,$", MR_Next},
75            {"\"threads\": 1,$", MR_Next},
76            {"\"iterations\": %int,$", MR_Next},
77            {"\"real_time\": %float,$", MR_Next},
78            {"\"cpu_time\": %float,$", MR_Next},
79            {"\"time_unit\": \"ns\",$", MR_Next},
80            {"\"t0_1000000DefaultBase\": 1\\.(0)*e\\+(0)*6,$", MR_Next},
81            {"\"t1_1000000Base1000\": 1\\.(0)*e\\+(0)*6,$", MR_Next},
82            {"\"t2_1000000Base1024\": 1\\.(0)*e\\+(0)*6,$", MR_Next},
83            {"\"t3_1048576Base1000\": 1\\.048576(0)*e\\+(0)*6,$", MR_Next},
84            {"\"t4_1048576Base1024\": 1\\.048576(0)*e\\+(0)*6$", MR_Next},
85            {"}", MR_Next}});
86 ADD_CASES(TC_JSONOut,
87           {{"\"name\": \"BM_Counters_Thousands/repeats:2_mean\",$"},
88            {"\"run_name\": \"BM_Counters_Thousands/repeats:2\",$", MR_Next},
89            {"\"run_type\": \"aggregate\",$", MR_Next},
90            {"\"repetitions\": 2,$", MR_Next},
91            {"\"threads\": 1,$", MR_Next},
92            {"\"aggregate_name\": \"mean\",$", MR_Next},
93            {"\"iterations\": 2,$", MR_Next},
94            {"\"real_time\": %float,$", MR_Next},
95            {"\"cpu_time\": %float,$", MR_Next},
96            {"\"time_unit\": \"ns\",$", MR_Next},
97            {"\"t0_1000000DefaultBase\": 1\\.(0)*e\\+(0)*6,$", MR_Next},
98            {"\"t1_1000000Base1000\": 1\\.(0)*e\\+(0)*6,$", MR_Next},
99            {"\"t2_1000000Base1024\": 1\\.(0)*e\\+(0)*6,$", MR_Next},
100            {"\"t3_1048576Base1000\": 1\\.048576(0)*e\\+(0)*6,$", MR_Next},
101            {"\"t4_1048576Base1024\": 1\\.048576(0)*e\\+(0)*6$", MR_Next},
102            {"}", MR_Next}});
103 ADD_CASES(TC_JSONOut,
104           {{"\"name\": \"BM_Counters_Thousands/repeats:2_median\",$"},
105            {"\"run_name\": \"BM_Counters_Thousands/repeats:2\",$", MR_Next},
106            {"\"run_type\": \"aggregate\",$", MR_Next},
107            {"\"repetitions\": 2,$", MR_Next},
108            {"\"threads\": 1,$", MR_Next},
109            {"\"aggregate_name\": \"median\",$", MR_Next},
110            {"\"iterations\": 2,$", MR_Next},
111            {"\"real_time\": %float,$", MR_Next},
112            {"\"cpu_time\": %float,$", MR_Next},
113            {"\"time_unit\": \"ns\",$", MR_Next},
114            {"\"t0_1000000DefaultBase\": 1\\.(0)*e\\+(0)*6,$", MR_Next},
115            {"\"t1_1000000Base1000\": 1\\.(0)*e\\+(0)*6,$", MR_Next},
116            {"\"t2_1000000Base1024\": 1\\.(0)*e\\+(0)*6,$", MR_Next},
117            {"\"t3_1048576Base1000\": 1\\.048576(0)*e\\+(0)*6,$", MR_Next},
118            {"\"t4_1048576Base1024\": 1\\.048576(0)*e\\+(0)*6$", MR_Next},
119            {"}", MR_Next}});
120 ADD_CASES(TC_JSONOut,
121           {{"\"name\": \"BM_Counters_Thousands/repeats:2_stddev\",$"},
122            {"\"run_name\": \"BM_Counters_Thousands/repeats:2\",$", MR_Next},
123            {"\"run_type\": \"aggregate\",$", MR_Next},
124            {"\"repetitions\": 2,$", MR_Next},
125            {"\"threads\": 1,$", MR_Next},
126            {"\"aggregate_name\": \"stddev\",$", MR_Next},
127            {"\"iterations\": 2,$", MR_Next},
128            {"\"real_time\": %float,$", MR_Next},
129            {"\"cpu_time\": %float,$", MR_Next},
130            {"\"time_unit\": \"ns\",$", MR_Next},
131            {"\"t0_1000000DefaultBase\": 0\\.(0)*e\\+(0)*,$", MR_Next},
132            {"\"t1_1000000Base1000\": 0\\.(0)*e\\+(0)*,$", MR_Next},
133            {"\"t2_1000000Base1024\": 0\\.(0)*e\\+(0)*,$", MR_Next},
134            {"\"t3_1048576Base1000\": 0\\.(0)*e\\+(0)*,$", MR_Next},
135            {"\"t4_1048576Base1024\": 0\\.(0)*e\\+(0)*$", MR_Next},
136            {"}", MR_Next}});
137 
138 ADD_CASES(
139     TC_CSVOut,
140     {{"^\"BM_Counters_Thousands/"
141       "repeats:2\",%csv_report,1e\\+(0)*6,1e\\+(0)*6,1e\\+(0)*6,1\\.04858e\\+("
142       "0)*6,1\\.04858e\\+(0)*6$"},
143      {"^\"BM_Counters_Thousands/"
144       "repeats:2\",%csv_report,1e\\+(0)*6,1e\\+(0)*6,1e\\+(0)*6,1\\.04858e\\+("
145       "0)*6,1\\.04858e\\+(0)*6$"},
146      {"^\"BM_Counters_Thousands/"
147       "repeats:2_mean\",%csv_report,1e\\+(0)*6,1e\\+(0)*6,1e\\+(0)*6,1\\."
148       "04858e\\+(0)*6,1\\.04858e\\+(0)*6$"},
149      {"^\"BM_Counters_Thousands/"
150       "repeats:2_median\",%csv_report,1e\\+(0)*6,1e\\+(0)*6,1e\\+(0)*6,1\\."
151       "04858e\\+(0)*6,1\\.04858e\\+(0)*6$"},
152      {"^\"BM_Counters_Thousands/repeats:2_stddev\",%csv_report,0,0,0,0,0$"}});
153 // VS2013 does not allow this function to be passed as a lambda argument
154 // to CHECK_BENCHMARK_RESULTS()
CheckThousands(Results const & e)155 void CheckThousands(Results const& e) {
156   if (e.name != "BM_Counters_Thousands/repeats:2")
157     return;  // Do not check the aggregates!
158 
159   // check that the values are within 0.01% of the expected values
160   CHECK_FLOAT_COUNTER_VALUE(e, "t0_1000000DefaultBase", EQ, 1000 * 1000,
161                             0.0001);
162   CHECK_FLOAT_COUNTER_VALUE(e, "t1_1000000Base1000", EQ, 1000 * 1000, 0.0001);
163   CHECK_FLOAT_COUNTER_VALUE(e, "t2_1000000Base1024", EQ, 1000 * 1000, 0.0001);
164   CHECK_FLOAT_COUNTER_VALUE(e, "t3_1048576Base1000", EQ, 1024 * 1024, 0.0001);
165   CHECK_FLOAT_COUNTER_VALUE(e, "t4_1048576Base1024", EQ, 1024 * 1024, 0.0001);
166 }
167 CHECK_BENCHMARK_RESULTS("BM_Counters_Thousands", &CheckThousands);
168 
169 // ========================================================================= //
170 // --------------------------- TEST CASES END ------------------------------ //
171 // ========================================================================= //
172 
main(int argc,char * argv[])173 int main(int argc, char* argv[]) { RunOutputTests(argc, argv); }
174