@@ -20,13 +20,16 @@ namespace {
2020int AddComplexityTest(const std::string& test_name,
2121 const std::string& big_o_test_name,
2222 const std::string& rms_test_name,
23- const std::string& big_o, int family_index) {
23+ const std::string& big_o, int family_index,
24+ const std::string& time_unit,
25+ const std::string& real_coefficient) {
2426 SetSubstitutions ({{" %name" , test_name},
2527 {" %bigo_name" , big_o_test_name},
2628 {" %rms_name" , rms_test_name},
2729 {" %bigo_str" , " [ ]* %float " + big_o},
2830 {" %bigo" , big_o},
29- {" %rms" , " [ ]*[0-9]+ %" }});
31+ {" %rms" , " [ ]*[0-9]+ %" },
32+ {" %unit" , time_unit}});
3033 AddCases (
3134 TC_ConsoleOut,
3235 {{" ^%bigo_name %bigo_str %bigo_str[ ]*$" },
@@ -44,9 +47,9 @@ int AddComplexityTest(const std::string& test_name,
4447 {" \" aggregate_name\" : \" BigO\" ,$" , MR_Next},
4548 {" \" aggregate_unit\" : \" time\" ,$" , MR_Next},
4649 {" \" cpu_coefficient\" : %float,$" , MR_Next},
47- {" \" real_coefficient\" : %float ,$" , MR_Next},
50+ {" \" real_coefficient\" : " + real_coefficient + " ,$" , MR_Next},
4851 {" \" big_o\" : \" %bigo\" ,$" , MR_Next},
49- {" \" time_unit\" : \" ns \" $" , MR_Next},
52+ {" \" time_unit\" : \" %unit \" $" , MR_Next},
5053 {" }" , MR_Next},
5154 {" \" name\" : \" %rms_name\" ,$" },
5255 {" \" family_index\" : " + std::to_string (family_index) + " ,$" , MR_Next},
@@ -104,15 +107,15 @@ constexpr char lambda_big_o_1[] = "f\\(N\\)";
104107
105108// Add enum tests
106109ADD_COMPLEXITY_CASES (one_test_name, big_o_1_test_name, rms_o_1_test_name,
107- enum_auto_big_o_1, /* family_index=*/ 0 );
110+ enum_auto_big_o_1, /* family_index=*/ 0 , " ns " , " %float " );
108111
109112// Add auto tests
110113ADD_COMPLEXITY_CASES (one_test_name, big_o_1_test_name, rms_o_1_test_name,
111- enum_auto_big_o_1, /* family_index=*/ 1 );
114+ enum_auto_big_o_1, /* family_index=*/ 1 , " ns " , " %float " );
112115
113116// Add lambda tests
114117ADD_COMPLEXITY_CASES (one_test_name, big_o_1_test_name, rms_o_1_test_name,
115- lambda_big_o_1, /* family_index=*/ 2 );
118+ lambda_big_o_1, /* family_index=*/ 2 , " ns " , " %float " );
116119
117120// ========================================================================= //
118121// --------------------------- Testing BigO O(N) --------------------------- //
@@ -161,15 +164,15 @@ constexpr char lambda_big_o_n[] = "f\\(N\\)";
161164
162165// Add enum tests
163166ADD_COMPLEXITY_CASES (n_test_name, big_o_n_test_name, rms_o_n_test_name,
164- enum_auto_big_o_n, /* family_index=*/ 3 );
167+ enum_auto_big_o_n, /* family_index=*/ 3 , " ns " , " %float " );
165168
166169// Add auto tests
167170ADD_COMPLEXITY_CASES (n_test_name, big_o_n_test_name, rms_o_n_test_name,
168- enum_auto_big_o_n, /* family_index=*/ 4 );
171+ enum_auto_big_o_n, /* family_index=*/ 4 , " ns " , " %float " );
169172
170173// Add lambda tests
171174ADD_COMPLEXITY_CASES (n_test_name, big_o_n_test_name, rms_o_n_test_name,
172- lambda_big_o_n, /* family_index=*/ 5 );
175+ lambda_big_o_n, /* family_index=*/ 5 , " ns " , " %float " );
173176
174177// ========================================================================= //
175178// ------------------------- Testing BigO O(NlgN) ------------------------- //
@@ -222,17 +225,17 @@ constexpr char lambda_big_o_n_lg_n[] = "f\\(N\\)";
222225// Add enum tests
223226ADD_COMPLEXITY_CASES (n_lg_n_test_name, big_o_n_lg_n_test_name,
224227 rms_o_n_lg_n_test_name, enum_auto_big_o_n_lg_n,
225- /* family_index=*/ 6 );
228+ /* family_index=*/ 6 , " ns " , " %float " );
226229
227230// NOTE: auto big-o is wron.g
228231ADD_COMPLEXITY_CASES (n_lg_n_test_name, big_o_n_lg_n_test_name,
229232 rms_o_n_lg_n_test_name, enum_auto_big_o_n_lg_n,
230- /* family_index=*/ 7 );
233+ /* family_index=*/ 7 , " ns " , " %float " );
231234
232235// // Add lambda tests
233236ADD_COMPLEXITY_CASES (n_lg_n_test_name, big_o_n_lg_n_test_name,
234237 rms_o_n_lg_n_test_name, lambda_big_o_n_lg_n,
235- /* family_index=*/ 8 );
238+ /* family_index=*/ 8 , " ns " , " %float " );
236239
237240// ========================================================================= //
238241// -------- Testing formatting of Complexity with captured args ------------ //
@@ -265,7 +268,36 @@ const std::string complexity_capture_name =
265268
266269ADD_COMPLEXITY_CASES (complexity_capture_name, complexity_capture_name + " _BigO" ,
267270 complexity_capture_name + " _RMS" , " N" ,
268- /* family_index=*/ 9 );
271+ /* family_index=*/ 9 , " ns" , " %float" );
272+
273+ // ========================================================================= //
274+ // ------------------- Testing BigO with a declared unit ------------------- //
275+ // ========================================================================= //
276+
277+ void BM_Complexity_O_N_ms (benchmark::State& state) {
278+ for (auto _ : state) {
279+ // 1us per iteration per entry, the 2048 size 50% slower so the RMS is
280+ // above zero, reported in milliseconds
281+ const double skew = (state.range (0 ) & (1 << 11 )) ? 1.5 : 1.0 ;
282+ state.SetIterationTime (static_cast <double >(state.range (0 )) * 1e-6 * skew);
283+ }
284+ state.SetComplexityN (state.range (0 ));
285+ }
286+ BENCHMARK (BM_Complexity_O_N_ms)
287+ ->RangeMultiplier (2 )
288+ ->Range(1 << 10 , 1 << 16 )
289+ ->UseManualTime()
290+ ->Unit(benchmark::kMillisecond )
291+ ->Complexity(benchmark::oN);
292+
293+ constexpr char n_ms_test_name[] = " BM_Complexity_O_N_ms/manual_time" ;
294+ constexpr char big_o_n_ms_test_name[] = " BM_Complexity_O_N_ms/manual_time_BigO" ;
295+ constexpr char rms_o_n_ms_test_name[] = " BM_Complexity_O_N_ms/manual_time_RMS" ;
296+
297+ ADD_COMPLEXITY_CASES (n_ms_test_name, big_o_n_ms_test_name, rms_o_n_ms_test_name,
298+ enum_auto_big_o_n, /* family_index=*/ 10 , " ms" ,
299+ " 1\\ .[0-9]+e-03" );
300+
269301} // end namespace
270302
271303// ========================================================================= //
0 commit comments