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            {"\"iterations\": %int,$", MR_Next},
57            {"\"real_time\": %float,$", MR_Next},
58            {"\"cpu_time\": %float,$", MR_Next},
59            {"\"time_unit\": \"ns\",$", MR_Next},
60            {"\"t0_1000000DefaultBase\": 1\\.(0)*e\\+(0)*6,$", MR_Next},
61            {"\"t1_1000000Base1000\": 1\\.(0)*e\\+(0)*6,$", MR_Next},
62            {"\"t2_1000000Base1024\": 1\\.(0)*e\\+(0)*6,$", MR_Next},
63            {"\"t3_1048576Base1000\": 1\\.048576(0)*e\\+(0)*6,$", MR_Next},
64            {"\"t4_1048576Base1024\": 1\\.048576(0)*e\\+(0)*6$", MR_Next},
65            {"}", MR_Next}});
66 ADD_CASES(TC_JSONOut,
67           {{"\"name\": \"BM_Counters_Thousands/repeats:2\",$"},
68            {"\"run_name\": \"BM_Counters_Thousands/repeats:2\",$", MR_Next},
69            {"\"run_type\": \"iteration\",$", MR_Next},
70            {"\"iterations\": %int,$", MR_Next},
71            {"\"real_time\": %float,$", MR_Next},
72            {"\"cpu_time\": %float,$", MR_Next},
73            {"\"time_unit\": \"ns\",$", MR_Next},
74            {"\"t0_1000000DefaultBase\": 1\\.(0)*e\\+(0)*6,$", MR_Next},
75            {"\"t1_1000000Base1000\": 1\\.(0)*e\\+(0)*6,$", MR_Next},
76            {"\"t2_1000000Base1024\": 1\\.(0)*e\\+(0)*6,$", MR_Next},
77            {"\"t3_1048576Base1000\": 1\\.048576(0)*e\\+(0)*6,$", MR_Next},
78            {"\"t4_1048576Base1024\": 1\\.048576(0)*e\\+(0)*6$", MR_Next},
79            {"}", MR_Next}});
80 ADD_CASES(TC_JSONOut,
81           {{"\"name\": \"BM_Counters_Thousands/repeats:2_mean\",$"},
82            {"\"run_name\": \"BM_Counters_Thousands/repeats:2\",$", MR_Next},
83            {"\"run_type\": \"aggregate\",$", MR_Next},
84            {"\"aggregate_name\": \"mean\",$", MR_Next},
85            {"\"iterations\": 2,$", MR_Next},
86            {"\"real_time\": %float,$", MR_Next},
87            {"\"cpu_time\": %float,$", MR_Next},
88            {"\"time_unit\": \"ns\",$", MR_Next},
89            {"\"t0_1000000DefaultBase\": 1\\.(0)*e\\+(0)*6,$", MR_Next},
90            {"\"t1_1000000Base1000\": 1\\.(0)*e\\+(0)*6,$", MR_Next},
91            {"\"t2_1000000Base1024\": 1\\.(0)*e\\+(0)*6,$", MR_Next},
92            {"\"t3_1048576Base1000\": 1\\.048576(0)*e\\+(0)*6,$", MR_Next},
93            {"\"t4_1048576Base1024\": 1\\.048576(0)*e\\+(0)*6$", MR_Next},
94            {"}", MR_Next}});
95 ADD_CASES(TC_JSONOut,
96           {{"\"name\": \"BM_Counters_Thousands/repeats:2_median\",$"},
97            {"\"run_name\": \"BM_Counters_Thousands/repeats:2\",$", MR_Next},
98            {"\"run_type\": \"aggregate\",$", MR_Next},
99            {"\"aggregate_name\": \"median\",$", MR_Next},
100            {"\"iterations\": 2,$", MR_Next},
101            {"\"real_time\": %float,$", MR_Next},
102            {"\"cpu_time\": %float,$", MR_Next},
103            {"\"time_unit\": \"ns\",$", MR_Next},
104            {"\"t0_1000000DefaultBase\": 1\\.(0)*e\\+(0)*6,$", MR_Next},
105            {"\"t1_1000000Base1000\": 1\\.(0)*e\\+(0)*6,$", MR_Next},
106            {"\"t2_1000000Base1024\": 1\\.(0)*e\\+(0)*6,$", MR_Next},
107            {"\"t3_1048576Base1000\": 1\\.048576(0)*e\\+(0)*6,$", MR_Next},
108            {"\"t4_1048576Base1024\": 1\\.048576(0)*e\\+(0)*6$", MR_Next},
109            {"}", MR_Next}});
110 ADD_CASES(TC_JSONOut,
111           {{"\"name\": \"BM_Counters_Thousands/repeats:2_stddev\",$"},
112            {"\"run_name\": \"BM_Counters_Thousands/repeats:2\",$", MR_Next},
113            {"\"run_type\": \"aggregate\",$", MR_Next},
114            {"\"aggregate_name\": \"stddev\",$", MR_Next},
115            {"\"iterations\": 2,$", MR_Next},
116            {"\"real_time\": %float,$", MR_Next},
117            {"\"cpu_time\": %float,$", MR_Next},
118            {"\"time_unit\": \"ns\",$", MR_Next},
119            {"\"t0_1000000DefaultBase\": 0\\.(0)*e\\+(0)*,$", MR_Next},
120            {"\"t1_1000000Base1000\": 0\\.(0)*e\\+(0)*,$", MR_Next},
121            {"\"t2_1000000Base1024\": 0\\.(0)*e\\+(0)*,$", MR_Next},
122            {"\"t3_1048576Base1000\": 0\\.(0)*e\\+(0)*,$", MR_Next},
123            {"\"t4_1048576Base1024\": 0\\.(0)*e\\+(0)*$", MR_Next},
124            {"}", MR_Next}});
125 
126 ADD_CASES(
127     TC_CSVOut,
128     {{"^\"BM_Counters_Thousands/"
129       "repeats:2\",%csv_report,1e\\+(0)*6,1e\\+(0)*6,1e\\+(0)*6,1\\.04858e\\+("
130       "0)*6,1\\.04858e\\+(0)*6$"},
131      {"^\"BM_Counters_Thousands/"
132       "repeats:2\",%csv_report,1e\\+(0)*6,1e\\+(0)*6,1e\\+(0)*6,1\\.04858e\\+("
133       "0)*6,1\\.04858e\\+(0)*6$"},
134      {"^\"BM_Counters_Thousands/"
135       "repeats:2_mean\",%csv_report,1e\\+(0)*6,1e\\+(0)*6,1e\\+(0)*6,1\\."
136       "04858e\\+(0)*6,1\\.04858e\\+(0)*6$"},
137      {"^\"BM_Counters_Thousands/"
138       "repeats:2_median\",%csv_report,1e\\+(0)*6,1e\\+(0)*6,1e\\+(0)*6,1\\."
139       "04858e\\+(0)*6,1\\.04858e\\+(0)*6$"},
140      {"^\"BM_Counters_Thousands/repeats:2_stddev\",%csv_report,0,0,0,0,0$"}});
141 // VS2013 does not allow this function to be passed as a lambda argument
142 // to CHECK_BENCHMARK_RESULTS()
CheckThousands(Results const & e)143 void CheckThousands(Results const& e) {
144   if (e.name != "BM_Counters_Thousands/repeats:2")
145     return;  // Do not check the aggregates!
146 
147   // check that the values are within 0.01% of the expected values
148   CHECK_FLOAT_COUNTER_VALUE(e, "t0_1000000DefaultBase", EQ, 1000 * 1000,
149                             0.0001);
150   CHECK_FLOAT_COUNTER_VALUE(e, "t1_1000000Base1000", EQ, 1000 * 1000, 0.0001);
151   CHECK_FLOAT_COUNTER_VALUE(e, "t2_1000000Base1024", EQ, 1000 * 1000, 0.0001);
152   CHECK_FLOAT_COUNTER_VALUE(e, "t3_1048576Base1000", EQ, 1024 * 1024, 0.0001);
153   CHECK_FLOAT_COUNTER_VALUE(e, "t4_1048576Base1024", EQ, 1024 * 1024, 0.0001);
154 }
155 CHECK_BENCHMARK_RESULTS("BM_Counters_Thousands", &CheckThousands);
156 
157 // ========================================================================= //
158 // --------------------------- TEST CASES END ------------------------------ //
159 // ========================================================================= //
160 
main(int argc,char * argv[])161 int main(int argc, char* argv[]) { RunOutputTests(argc, argv); }
162