[docs] Add LICENSE.txt to the root of the mono-repo
[llvm-project.git] / third-party / benchmark / test / user_counters_thousands_test.cc
bloba42683b32fa7b2c060e023ed5b6ad21dba770ec2
2 #undef NDEBUG
4 #include "benchmark/benchmark.h"
5 #include "output_test.h"
7 // ========================================================================= //
8 // ------------------------ Thousands Customisation ------------------------ //
9 // ========================================================================= //
11 void BM_Counters_Thousands(benchmark::State& state) {
12 for (auto _ : state) {
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 });
28 BENCHMARK(BM_Counters_Thousands)->Repetitions(2);
29 ADD_CASES(
30 TC_ConsoleOut,
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 {"\"family_index\": 0,$", MR_Next},
55 {"\"per_family_instance_index\": 0,$", MR_Next},
56 {"\"run_name\": \"BM_Counters_Thousands/repeats:2\",$", MR_Next},
57 {"\"run_type\": \"iteration\",$", MR_Next},
58 {"\"repetitions\": 2,$", MR_Next},
59 {"\"repetition_index\": 0,$", MR_Next},
60 {"\"threads\": 1,$", MR_Next},
61 {"\"iterations\": %int,$", MR_Next},
62 {"\"real_time\": %float,$", MR_Next},
63 {"\"cpu_time\": %float,$", MR_Next},
64 {"\"time_unit\": \"ns\",$", MR_Next},
65 {"\"t0_1000000DefaultBase\": 1\\.(0)*e\\+(0)*6,$", MR_Next},
66 {"\"t1_1000000Base1000\": 1\\.(0)*e\\+(0)*6,$", MR_Next},
67 {"\"t2_1000000Base1024\": 1\\.(0)*e\\+(0)*6,$", MR_Next},
68 {"\"t3_1048576Base1000\": 1\\.048576(0)*e\\+(0)*6,$", MR_Next},
69 {"\"t4_1048576Base1024\": 1\\.048576(0)*e\\+(0)*6$", MR_Next},
70 {"}", MR_Next}});
71 ADD_CASES(TC_JSONOut,
72 {{"\"name\": \"BM_Counters_Thousands/repeats:2\",$"},
73 {"\"family_index\": 0,$", MR_Next},
74 {"\"per_family_instance_index\": 0,$", MR_Next},
75 {"\"run_name\": \"BM_Counters_Thousands/repeats:2\",$", MR_Next},
76 {"\"run_type\": \"iteration\",$", MR_Next},
77 {"\"repetitions\": 2,$", MR_Next},
78 {"\"repetition_index\": 1,$", MR_Next},
79 {"\"threads\": 1,$", MR_Next},
80 {"\"iterations\": %int,$", MR_Next},
81 {"\"real_time\": %float,$", MR_Next},
82 {"\"cpu_time\": %float,$", MR_Next},
83 {"\"time_unit\": \"ns\",$", MR_Next},
84 {"\"t0_1000000DefaultBase\": 1\\.(0)*e\\+(0)*6,$", MR_Next},
85 {"\"t1_1000000Base1000\": 1\\.(0)*e\\+(0)*6,$", MR_Next},
86 {"\"t2_1000000Base1024\": 1\\.(0)*e\\+(0)*6,$", MR_Next},
87 {"\"t3_1048576Base1000\": 1\\.048576(0)*e\\+(0)*6,$", MR_Next},
88 {"\"t4_1048576Base1024\": 1\\.048576(0)*e\\+(0)*6$", MR_Next},
89 {"}", MR_Next}});
90 ADD_CASES(TC_JSONOut,
91 {{"\"name\": \"BM_Counters_Thousands/repeats:2_mean\",$"},
92 {"\"family_index\": 0,$", MR_Next},
93 {"\"per_family_instance_index\": 0,$", MR_Next},
94 {"\"run_name\": \"BM_Counters_Thousands/repeats:2\",$", MR_Next},
95 {"\"run_type\": \"aggregate\",$", MR_Next},
96 {"\"repetitions\": 2,$", MR_Next},
97 {"\"threads\": 1,$", MR_Next},
98 {"\"aggregate_name\": \"mean\",$", MR_Next},
99 {"\"aggregate_unit\": \"time\",$", 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_median\",$"},
112 {"\"family_index\": 0,$", MR_Next},
113 {"\"per_family_instance_index\": 0,$", MR_Next},
114 {"\"run_name\": \"BM_Counters_Thousands/repeats:2\",$", MR_Next},
115 {"\"run_type\": \"aggregate\",$", MR_Next},
116 {"\"repetitions\": 2,$", MR_Next},
117 {"\"threads\": 1,$", MR_Next},
118 {"\"aggregate_name\": \"median\",$", MR_Next},
119 {"\"aggregate_unit\": \"time\",$", MR_Next},
120 {"\"iterations\": 2,$", MR_Next},
121 {"\"real_time\": %float,$", MR_Next},
122 {"\"cpu_time\": %float,$", MR_Next},
123 {"\"time_unit\": \"ns\",$", MR_Next},
124 {"\"t0_1000000DefaultBase\": 1\\.(0)*e\\+(0)*6,$", MR_Next},
125 {"\"t1_1000000Base1000\": 1\\.(0)*e\\+(0)*6,$", MR_Next},
126 {"\"t2_1000000Base1024\": 1\\.(0)*e\\+(0)*6,$", MR_Next},
127 {"\"t3_1048576Base1000\": 1\\.048576(0)*e\\+(0)*6,$", MR_Next},
128 {"\"t4_1048576Base1024\": 1\\.048576(0)*e\\+(0)*6$", MR_Next},
129 {"}", MR_Next}});
130 ADD_CASES(TC_JSONOut,
131 {{"\"name\": \"BM_Counters_Thousands/repeats:2_stddev\",$"},
132 {"\"family_index\": 0,$", MR_Next},
133 {"\"per_family_instance_index\": 0,$", MR_Next},
134 {"\"run_name\": \"BM_Counters_Thousands/repeats:2\",$", MR_Next},
135 {"\"run_type\": \"aggregate\",$", MR_Next},
136 {"\"repetitions\": 2,$", MR_Next},
137 {"\"threads\": 1,$", MR_Next},
138 {"\"aggregate_name\": \"stddev\",$", MR_Next},
139 {"\"aggregate_unit\": \"time\",$", MR_Next},
140 {"\"iterations\": 2,$", MR_Next},
141 {"\"real_time\": %float,$", MR_Next},
142 {"\"cpu_time\": %float,$", MR_Next},
143 {"\"time_unit\": \"ns\",$", MR_Next},
144 {"\"t0_1000000DefaultBase\": 0\\.(0)*e\\+(0)*,$", MR_Next},
145 {"\"t1_1000000Base1000\": 0\\.(0)*e\\+(0)*,$", MR_Next},
146 {"\"t2_1000000Base1024\": 0\\.(0)*e\\+(0)*,$", MR_Next},
147 {"\"t3_1048576Base1000\": 0\\.(0)*e\\+(0)*,$", MR_Next},
148 {"\"t4_1048576Base1024\": 0\\.(0)*e\\+(0)*$", MR_Next},
149 {"}", MR_Next}});
151 ADD_CASES(
152 TC_CSVOut,
153 {{"^\"BM_Counters_Thousands/"
154 "repeats:2\",%csv_report,1e\\+(0)*6,1e\\+(0)*6,1e\\+(0)*6,1\\.04858e\\+("
155 "0)*6,1\\.04858e\\+(0)*6$"},
156 {"^\"BM_Counters_Thousands/"
157 "repeats:2\",%csv_report,1e\\+(0)*6,1e\\+(0)*6,1e\\+(0)*6,1\\.04858e\\+("
158 "0)*6,1\\.04858e\\+(0)*6$"},
159 {"^\"BM_Counters_Thousands/"
160 "repeats:2_mean\",%csv_report,1e\\+(0)*6,1e\\+(0)*6,1e\\+(0)*6,1\\."
161 "04858e\\+(0)*6,1\\.04858e\\+(0)*6$"},
162 {"^\"BM_Counters_Thousands/"
163 "repeats:2_median\",%csv_report,1e\\+(0)*6,1e\\+(0)*6,1e\\+(0)*6,1\\."
164 "04858e\\+(0)*6,1\\.04858e\\+(0)*6$"},
165 {"^\"BM_Counters_Thousands/repeats:2_stddev\",%csv_report,0,0,0,0,0$"}});
166 // VS2013 does not allow this function to be passed as a lambda argument
167 // to CHECK_BENCHMARK_RESULTS()
168 void CheckThousands(Results const& e) {
169 if (e.name != "BM_Counters_Thousands/repeats:2")
170 return; // Do not check the aggregates!
172 // check that the values are within 0.01% of the expected values
173 CHECK_FLOAT_COUNTER_VALUE(e, "t0_1000000DefaultBase", EQ, 1000 * 1000,
174 0.0001);
175 CHECK_FLOAT_COUNTER_VALUE(e, "t1_1000000Base1000", EQ, 1000 * 1000, 0.0001);
176 CHECK_FLOAT_COUNTER_VALUE(e, "t2_1000000Base1024", EQ, 1000 * 1000, 0.0001);
177 CHECK_FLOAT_COUNTER_VALUE(e, "t3_1048576Base1000", EQ, 1024 * 1024, 0.0001);
178 CHECK_FLOAT_COUNTER_VALUE(e, "t4_1048576Base1024", EQ, 1024 * 1024, 0.0001);
180 CHECK_BENCHMARK_RESULTS("BM_Counters_Thousands", &CheckThousands);
182 // ========================================================================= //
183 // --------------------------- TEST CASES END ------------------------------ //
184 // ========================================================================= //
186 int main(int argc, char* argv[]) { RunOutputTests(argc, argv); }