1a8c51b3fSopenharmony_ci 2a8c51b3fSopenharmony_ci#undef NDEBUG 3a8c51b3fSopenharmony_ci 4a8c51b3fSopenharmony_ci#include "benchmark/benchmark.h" 5a8c51b3fSopenharmony_ci#include "output_test.h" 6a8c51b3fSopenharmony_ci 7a8c51b3fSopenharmony_ci// ========================================================================= // 8a8c51b3fSopenharmony_ci// ---------------------- Testing Prologue Output -------------------------- // 9a8c51b3fSopenharmony_ci// ========================================================================= // 10a8c51b3fSopenharmony_ci 11a8c51b3fSopenharmony_ci// clang-format off 12a8c51b3fSopenharmony_ci 13a8c51b3fSopenharmony_ciADD_CASES(TC_ConsoleOut, 14a8c51b3fSopenharmony_ci {{"^[-]+$", MR_Next}, 15a8c51b3fSopenharmony_ci {"^Benchmark %s Time %s CPU %s Iterations UserCounters...$", MR_Next}, 16a8c51b3fSopenharmony_ci {"^[-]+$", MR_Next}}); 17a8c51b3fSopenharmony_ciADD_CASES(TC_CSVOut, {{"%csv_header,\"bar\",\"foo\""}}); 18a8c51b3fSopenharmony_ci 19a8c51b3fSopenharmony_ci// clang-format on 20a8c51b3fSopenharmony_ci 21a8c51b3fSopenharmony_ci// ========================================================================= // 22a8c51b3fSopenharmony_ci// ------------------------- Simple Counters Output ------------------------ // 23a8c51b3fSopenharmony_ci// ========================================================================= // 24a8c51b3fSopenharmony_ci 25a8c51b3fSopenharmony_civoid BM_Counters_Simple(benchmark::State& state) { 26a8c51b3fSopenharmony_ci for (auto _ : state) { 27a8c51b3fSopenharmony_ci } 28a8c51b3fSopenharmony_ci state.counters["foo"] = 1; 29a8c51b3fSopenharmony_ci state.counters["bar"] = 2 * static_cast<double>(state.iterations()); 30a8c51b3fSopenharmony_ci} 31a8c51b3fSopenharmony_ciBENCHMARK(BM_Counters_Simple); 32a8c51b3fSopenharmony_ciADD_CASES(TC_ConsoleOut, 33a8c51b3fSopenharmony_ci {{"^BM_Counters_Simple %console_report bar=%hrfloat foo=%hrfloat$"}}); 34a8c51b3fSopenharmony_ciADD_CASES(TC_JSONOut, {{"\"name\": \"BM_Counters_Simple\",$"}, 35a8c51b3fSopenharmony_ci {"\"family_index\": 0,$", MR_Next}, 36a8c51b3fSopenharmony_ci {"\"per_family_instance_index\": 0,$", MR_Next}, 37a8c51b3fSopenharmony_ci {"\"run_name\": \"BM_Counters_Simple\",$", MR_Next}, 38a8c51b3fSopenharmony_ci {"\"run_type\": \"iteration\",$", MR_Next}, 39a8c51b3fSopenharmony_ci {"\"repetitions\": 1,$", MR_Next}, 40a8c51b3fSopenharmony_ci {"\"repetition_index\": 0,$", MR_Next}, 41a8c51b3fSopenharmony_ci {"\"threads\": 1,$", MR_Next}, 42a8c51b3fSopenharmony_ci {"\"iterations\": %int,$", MR_Next}, 43a8c51b3fSopenharmony_ci {"\"real_time\": %float,$", MR_Next}, 44a8c51b3fSopenharmony_ci {"\"cpu_time\": %float,$", MR_Next}, 45a8c51b3fSopenharmony_ci {"\"time_unit\": \"ns\",$", MR_Next}, 46a8c51b3fSopenharmony_ci {"\"bar\": %float,$", MR_Next}, 47a8c51b3fSopenharmony_ci {"\"foo\": %float$", MR_Next}, 48a8c51b3fSopenharmony_ci {"}", MR_Next}}); 49a8c51b3fSopenharmony_ciADD_CASES(TC_CSVOut, {{"^\"BM_Counters_Simple\",%csv_report,%float,%float$"}}); 50a8c51b3fSopenharmony_ci// VS2013 does not allow this function to be passed as a lambda argument 51a8c51b3fSopenharmony_ci// to CHECK_BENCHMARK_RESULTS() 52a8c51b3fSopenharmony_civoid CheckSimple(Results const& e) { 53a8c51b3fSopenharmony_ci double its = e.NumIterations(); 54a8c51b3fSopenharmony_ci CHECK_COUNTER_VALUE(e, int, "foo", EQ, 1); 55a8c51b3fSopenharmony_ci // check that the value of bar is within 0.1% of the expected value 56a8c51b3fSopenharmony_ci CHECK_FLOAT_COUNTER_VALUE(e, "bar", EQ, 2. * its, 0.001); 57a8c51b3fSopenharmony_ci} 58a8c51b3fSopenharmony_ciCHECK_BENCHMARK_RESULTS("BM_Counters_Simple", &CheckSimple); 59a8c51b3fSopenharmony_ci 60a8c51b3fSopenharmony_ci// ========================================================================= // 61a8c51b3fSopenharmony_ci// --------------------- Counters+Items+Bytes/s Output --------------------- // 62a8c51b3fSopenharmony_ci// ========================================================================= // 63a8c51b3fSopenharmony_ci 64a8c51b3fSopenharmony_cinamespace { 65a8c51b3fSopenharmony_ciint num_calls1 = 0; 66a8c51b3fSopenharmony_ci} 67a8c51b3fSopenharmony_civoid BM_Counters_WithBytesAndItemsPSec(benchmark::State& state) { 68a8c51b3fSopenharmony_ci for (auto _ : state) { 69a8c51b3fSopenharmony_ci // This test requires a non-zero CPU time to avoid divide-by-zero 70a8c51b3fSopenharmony_ci auto iterations = state.iterations(); 71a8c51b3fSopenharmony_ci benchmark::DoNotOptimize(iterations); 72a8c51b3fSopenharmony_ci } 73a8c51b3fSopenharmony_ci state.counters["foo"] = 1; 74a8c51b3fSopenharmony_ci state.counters["bar"] = ++num_calls1; 75a8c51b3fSopenharmony_ci state.SetBytesProcessed(364); 76a8c51b3fSopenharmony_ci state.SetItemsProcessed(150); 77a8c51b3fSopenharmony_ci} 78a8c51b3fSopenharmony_ciBENCHMARK(BM_Counters_WithBytesAndItemsPSec); 79a8c51b3fSopenharmony_ciADD_CASES(TC_ConsoleOut, {{"^BM_Counters_WithBytesAndItemsPSec %console_report " 80a8c51b3fSopenharmony_ci "bar=%hrfloat bytes_per_second=%hrfloat/s " 81a8c51b3fSopenharmony_ci "foo=%hrfloat items_per_second=%hrfloat/s$"}}); 82a8c51b3fSopenharmony_ciADD_CASES(TC_JSONOut, 83a8c51b3fSopenharmony_ci {{"\"name\": \"BM_Counters_WithBytesAndItemsPSec\",$"}, 84a8c51b3fSopenharmony_ci {"\"family_index\": 1,$", MR_Next}, 85a8c51b3fSopenharmony_ci {"\"per_family_instance_index\": 0,$", MR_Next}, 86a8c51b3fSopenharmony_ci {"\"run_name\": \"BM_Counters_WithBytesAndItemsPSec\",$", MR_Next}, 87a8c51b3fSopenharmony_ci {"\"run_type\": \"iteration\",$", MR_Next}, 88a8c51b3fSopenharmony_ci {"\"repetitions\": 1,$", MR_Next}, 89a8c51b3fSopenharmony_ci {"\"repetition_index\": 0,$", MR_Next}, 90a8c51b3fSopenharmony_ci {"\"threads\": 1,$", MR_Next}, 91a8c51b3fSopenharmony_ci {"\"iterations\": %int,$", MR_Next}, 92a8c51b3fSopenharmony_ci {"\"real_time\": %float,$", MR_Next}, 93a8c51b3fSopenharmony_ci {"\"cpu_time\": %float,$", MR_Next}, 94a8c51b3fSopenharmony_ci {"\"time_unit\": \"ns\",$", MR_Next}, 95a8c51b3fSopenharmony_ci {"\"bar\": %float,$", MR_Next}, 96a8c51b3fSopenharmony_ci {"\"bytes_per_second\": %float,$", MR_Next}, 97a8c51b3fSopenharmony_ci {"\"foo\": %float,$", MR_Next}, 98a8c51b3fSopenharmony_ci {"\"items_per_second\": %float$", MR_Next}, 99a8c51b3fSopenharmony_ci {"}", MR_Next}}); 100a8c51b3fSopenharmony_ciADD_CASES(TC_CSVOut, {{"^\"BM_Counters_WithBytesAndItemsPSec\"," 101a8c51b3fSopenharmony_ci "%csv_bytes_items_report,%float,%float$"}}); 102a8c51b3fSopenharmony_ci// VS2013 does not allow this function to be passed as a lambda argument 103a8c51b3fSopenharmony_ci// to CHECK_BENCHMARK_RESULTS() 104a8c51b3fSopenharmony_civoid CheckBytesAndItemsPSec(Results const& e) { 105a8c51b3fSopenharmony_ci double t = e.DurationCPUTime(); // this (and not real time) is the time used 106a8c51b3fSopenharmony_ci CHECK_COUNTER_VALUE(e, int, "foo", EQ, 1); 107a8c51b3fSopenharmony_ci CHECK_COUNTER_VALUE(e, int, "bar", EQ, num_calls1); 108a8c51b3fSopenharmony_ci // check that the values are within 0.1% of the expected values 109a8c51b3fSopenharmony_ci CHECK_FLOAT_RESULT_VALUE(e, "bytes_per_second", EQ, 364. / t, 0.001); 110a8c51b3fSopenharmony_ci CHECK_FLOAT_RESULT_VALUE(e, "items_per_second", EQ, 150. / t, 0.001); 111a8c51b3fSopenharmony_ci} 112a8c51b3fSopenharmony_ciCHECK_BENCHMARK_RESULTS("BM_Counters_WithBytesAndItemsPSec", 113a8c51b3fSopenharmony_ci &CheckBytesAndItemsPSec); 114a8c51b3fSopenharmony_ci 115a8c51b3fSopenharmony_ci// ========================================================================= // 116a8c51b3fSopenharmony_ci// ------------------------- Rate Counters Output -------------------------- // 117a8c51b3fSopenharmony_ci// ========================================================================= // 118a8c51b3fSopenharmony_ci 119a8c51b3fSopenharmony_civoid BM_Counters_Rate(benchmark::State& state) { 120a8c51b3fSopenharmony_ci for (auto _ : state) { 121a8c51b3fSopenharmony_ci // This test requires a non-zero CPU time to avoid divide-by-zero 122a8c51b3fSopenharmony_ci auto iterations = state.iterations(); 123a8c51b3fSopenharmony_ci benchmark::DoNotOptimize(iterations); 124a8c51b3fSopenharmony_ci } 125a8c51b3fSopenharmony_ci namespace bm = benchmark; 126a8c51b3fSopenharmony_ci state.counters["foo"] = bm::Counter{1, bm::Counter::kIsRate}; 127a8c51b3fSopenharmony_ci state.counters["bar"] = bm::Counter{2, bm::Counter::kIsRate}; 128a8c51b3fSopenharmony_ci} 129a8c51b3fSopenharmony_ciBENCHMARK(BM_Counters_Rate); 130a8c51b3fSopenharmony_ciADD_CASES( 131a8c51b3fSopenharmony_ci TC_ConsoleOut, 132a8c51b3fSopenharmony_ci {{"^BM_Counters_Rate %console_report bar=%hrfloat/s foo=%hrfloat/s$"}}); 133a8c51b3fSopenharmony_ciADD_CASES(TC_JSONOut, {{"\"name\": \"BM_Counters_Rate\",$"}, 134a8c51b3fSopenharmony_ci {"\"family_index\": 2,$", MR_Next}, 135a8c51b3fSopenharmony_ci {"\"per_family_instance_index\": 0,$", MR_Next}, 136a8c51b3fSopenharmony_ci {"\"run_name\": \"BM_Counters_Rate\",$", MR_Next}, 137a8c51b3fSopenharmony_ci {"\"run_type\": \"iteration\",$", MR_Next}, 138a8c51b3fSopenharmony_ci {"\"repetitions\": 1,$", MR_Next}, 139a8c51b3fSopenharmony_ci {"\"repetition_index\": 0,$", MR_Next}, 140a8c51b3fSopenharmony_ci {"\"threads\": 1,$", MR_Next}, 141a8c51b3fSopenharmony_ci {"\"iterations\": %int,$", MR_Next}, 142a8c51b3fSopenharmony_ci {"\"real_time\": %float,$", MR_Next}, 143a8c51b3fSopenharmony_ci {"\"cpu_time\": %float,$", MR_Next}, 144a8c51b3fSopenharmony_ci {"\"time_unit\": \"ns\",$", MR_Next}, 145a8c51b3fSopenharmony_ci {"\"bar\": %float,$", MR_Next}, 146a8c51b3fSopenharmony_ci {"\"foo\": %float$", MR_Next}, 147a8c51b3fSopenharmony_ci {"}", MR_Next}}); 148a8c51b3fSopenharmony_ciADD_CASES(TC_CSVOut, {{"^\"BM_Counters_Rate\",%csv_report,%float,%float$"}}); 149a8c51b3fSopenharmony_ci// VS2013 does not allow this function to be passed as a lambda argument 150a8c51b3fSopenharmony_ci// to CHECK_BENCHMARK_RESULTS() 151a8c51b3fSopenharmony_civoid CheckRate(Results const& e) { 152a8c51b3fSopenharmony_ci double t = e.DurationCPUTime(); // this (and not real time) is the time used 153a8c51b3fSopenharmony_ci // check that the values are within 0.1% of the expected values 154a8c51b3fSopenharmony_ci CHECK_FLOAT_COUNTER_VALUE(e, "foo", EQ, 1. / t, 0.001); 155a8c51b3fSopenharmony_ci CHECK_FLOAT_COUNTER_VALUE(e, "bar", EQ, 2. / t, 0.001); 156a8c51b3fSopenharmony_ci} 157a8c51b3fSopenharmony_ciCHECK_BENCHMARK_RESULTS("BM_Counters_Rate", &CheckRate); 158a8c51b3fSopenharmony_ci 159a8c51b3fSopenharmony_ci// ========================================================================= // 160a8c51b3fSopenharmony_ci// ----------------------- Inverted Counters Output ------------------------ // 161a8c51b3fSopenharmony_ci// ========================================================================= // 162a8c51b3fSopenharmony_ci 163a8c51b3fSopenharmony_civoid BM_Invert(benchmark::State& state) { 164a8c51b3fSopenharmony_ci for (auto _ : state) { 165a8c51b3fSopenharmony_ci // This test requires a non-zero CPU time to avoid divide-by-zero 166a8c51b3fSopenharmony_ci auto iterations = state.iterations(); 167a8c51b3fSopenharmony_ci benchmark::DoNotOptimize(iterations); 168a8c51b3fSopenharmony_ci } 169a8c51b3fSopenharmony_ci namespace bm = benchmark; 170a8c51b3fSopenharmony_ci state.counters["foo"] = bm::Counter{0.0001, bm::Counter::kInvert}; 171a8c51b3fSopenharmony_ci state.counters["bar"] = bm::Counter{10000, bm::Counter::kInvert}; 172a8c51b3fSopenharmony_ci} 173a8c51b3fSopenharmony_ciBENCHMARK(BM_Invert); 174a8c51b3fSopenharmony_ciADD_CASES(TC_ConsoleOut, 175a8c51b3fSopenharmony_ci {{"^BM_Invert %console_report bar=%hrfloatu foo=%hrfloatk$"}}); 176a8c51b3fSopenharmony_ciADD_CASES(TC_JSONOut, {{"\"name\": \"BM_Invert\",$"}, 177a8c51b3fSopenharmony_ci {"\"family_index\": 3,$", MR_Next}, 178a8c51b3fSopenharmony_ci {"\"per_family_instance_index\": 0,$", MR_Next}, 179a8c51b3fSopenharmony_ci {"\"run_name\": \"BM_Invert\",$", MR_Next}, 180a8c51b3fSopenharmony_ci {"\"run_type\": \"iteration\",$", MR_Next}, 181a8c51b3fSopenharmony_ci {"\"repetitions\": 1,$", MR_Next}, 182a8c51b3fSopenharmony_ci {"\"repetition_index\": 0,$", MR_Next}, 183a8c51b3fSopenharmony_ci {"\"threads\": 1,$", MR_Next}, 184a8c51b3fSopenharmony_ci {"\"iterations\": %int,$", MR_Next}, 185a8c51b3fSopenharmony_ci {"\"real_time\": %float,$", MR_Next}, 186a8c51b3fSopenharmony_ci {"\"cpu_time\": %float,$", MR_Next}, 187a8c51b3fSopenharmony_ci {"\"time_unit\": \"ns\",$", MR_Next}, 188a8c51b3fSopenharmony_ci {"\"bar\": %float,$", MR_Next}, 189a8c51b3fSopenharmony_ci {"\"foo\": %float$", MR_Next}, 190a8c51b3fSopenharmony_ci {"}", MR_Next}}); 191a8c51b3fSopenharmony_ciADD_CASES(TC_CSVOut, {{"^\"BM_Invert\",%csv_report,%float,%float$"}}); 192a8c51b3fSopenharmony_ci// VS2013 does not allow this function to be passed as a lambda argument 193a8c51b3fSopenharmony_ci// to CHECK_BENCHMARK_RESULTS() 194a8c51b3fSopenharmony_civoid CheckInvert(Results const& e) { 195a8c51b3fSopenharmony_ci CHECK_FLOAT_COUNTER_VALUE(e, "foo", EQ, 10000, 0.0001); 196a8c51b3fSopenharmony_ci CHECK_FLOAT_COUNTER_VALUE(e, "bar", EQ, 0.0001, 0.0001); 197a8c51b3fSopenharmony_ci} 198a8c51b3fSopenharmony_ciCHECK_BENCHMARK_RESULTS("BM_Invert", &CheckInvert); 199a8c51b3fSopenharmony_ci 200a8c51b3fSopenharmony_ci// ========================================================================= // 201a8c51b3fSopenharmony_ci// --------------------- InvertedRate Counters Output ---------------------- // 202a8c51b3fSopenharmony_ci// ========================================================================= // 203a8c51b3fSopenharmony_ci 204a8c51b3fSopenharmony_civoid BM_Counters_InvertedRate(benchmark::State& state) { 205a8c51b3fSopenharmony_ci for (auto _ : state) { 206a8c51b3fSopenharmony_ci // This test requires a non-zero CPU time to avoid divide-by-zero 207a8c51b3fSopenharmony_ci auto iterations = state.iterations(); 208a8c51b3fSopenharmony_ci benchmark::DoNotOptimize(iterations); 209a8c51b3fSopenharmony_ci } 210a8c51b3fSopenharmony_ci namespace bm = benchmark; 211a8c51b3fSopenharmony_ci state.counters["foo"] = 212a8c51b3fSopenharmony_ci bm::Counter{1, bm::Counter::kIsRate | bm::Counter::kInvert}; 213a8c51b3fSopenharmony_ci state.counters["bar"] = 214a8c51b3fSopenharmony_ci bm::Counter{8192, bm::Counter::kIsRate | bm::Counter::kInvert}; 215a8c51b3fSopenharmony_ci} 216a8c51b3fSopenharmony_ciBENCHMARK(BM_Counters_InvertedRate); 217a8c51b3fSopenharmony_ciADD_CASES(TC_ConsoleOut, {{"^BM_Counters_InvertedRate %console_report " 218a8c51b3fSopenharmony_ci "bar=%hrfloats foo=%hrfloats$"}}); 219a8c51b3fSopenharmony_ciADD_CASES(TC_JSONOut, 220a8c51b3fSopenharmony_ci {{"\"name\": \"BM_Counters_InvertedRate\",$"}, 221a8c51b3fSopenharmony_ci {"\"family_index\": 4,$", MR_Next}, 222a8c51b3fSopenharmony_ci {"\"per_family_instance_index\": 0,$", MR_Next}, 223a8c51b3fSopenharmony_ci {"\"run_name\": \"BM_Counters_InvertedRate\",$", MR_Next}, 224a8c51b3fSopenharmony_ci {"\"run_type\": \"iteration\",$", MR_Next}, 225a8c51b3fSopenharmony_ci {"\"repetitions\": 1,$", MR_Next}, 226a8c51b3fSopenharmony_ci {"\"repetition_index\": 0,$", MR_Next}, 227a8c51b3fSopenharmony_ci {"\"threads\": 1,$", MR_Next}, 228a8c51b3fSopenharmony_ci {"\"iterations\": %int,$", MR_Next}, 229a8c51b3fSopenharmony_ci {"\"real_time\": %float,$", MR_Next}, 230a8c51b3fSopenharmony_ci {"\"cpu_time\": %float,$", MR_Next}, 231a8c51b3fSopenharmony_ci {"\"time_unit\": \"ns\",$", MR_Next}, 232a8c51b3fSopenharmony_ci {"\"bar\": %float,$", MR_Next}, 233a8c51b3fSopenharmony_ci {"\"foo\": %float$", MR_Next}, 234a8c51b3fSopenharmony_ci {"}", MR_Next}}); 235a8c51b3fSopenharmony_ciADD_CASES(TC_CSVOut, 236a8c51b3fSopenharmony_ci {{"^\"BM_Counters_InvertedRate\",%csv_report,%float,%float$"}}); 237a8c51b3fSopenharmony_ci// VS2013 does not allow this function to be passed as a lambda argument 238a8c51b3fSopenharmony_ci// to CHECK_BENCHMARK_RESULTS() 239a8c51b3fSopenharmony_civoid CheckInvertedRate(Results const& e) { 240a8c51b3fSopenharmony_ci double t = e.DurationCPUTime(); // this (and not real time) is the time used 241a8c51b3fSopenharmony_ci // check that the values are within 0.1% of the expected values 242a8c51b3fSopenharmony_ci CHECK_FLOAT_COUNTER_VALUE(e, "foo", EQ, t, 0.001); 243a8c51b3fSopenharmony_ci CHECK_FLOAT_COUNTER_VALUE(e, "bar", EQ, t / 8192.0, 0.001); 244a8c51b3fSopenharmony_ci} 245a8c51b3fSopenharmony_ciCHECK_BENCHMARK_RESULTS("BM_Counters_InvertedRate", &CheckInvertedRate); 246a8c51b3fSopenharmony_ci 247a8c51b3fSopenharmony_ci// ========================================================================= // 248a8c51b3fSopenharmony_ci// ------------------------- Thread Counters Output ------------------------ // 249a8c51b3fSopenharmony_ci// ========================================================================= // 250a8c51b3fSopenharmony_ci 251a8c51b3fSopenharmony_civoid BM_Counters_Threads(benchmark::State& state) { 252a8c51b3fSopenharmony_ci for (auto _ : state) { 253a8c51b3fSopenharmony_ci } 254a8c51b3fSopenharmony_ci state.counters["foo"] = 1; 255a8c51b3fSopenharmony_ci state.counters["bar"] = 2; 256a8c51b3fSopenharmony_ci} 257a8c51b3fSopenharmony_ciBENCHMARK(BM_Counters_Threads)->ThreadRange(1, 8); 258a8c51b3fSopenharmony_ciADD_CASES(TC_ConsoleOut, {{"^BM_Counters_Threads/threads:%int %console_report " 259a8c51b3fSopenharmony_ci "bar=%hrfloat foo=%hrfloat$"}}); 260a8c51b3fSopenharmony_ciADD_CASES(TC_JSONOut, 261a8c51b3fSopenharmony_ci {{"\"name\": \"BM_Counters_Threads/threads:%int\",$"}, 262a8c51b3fSopenharmony_ci {"\"family_index\": 5,$", MR_Next}, 263a8c51b3fSopenharmony_ci {"\"per_family_instance_index\": 0,$", MR_Next}, 264a8c51b3fSopenharmony_ci {"\"run_name\": \"BM_Counters_Threads/threads:%int\",$", MR_Next}, 265a8c51b3fSopenharmony_ci {"\"run_type\": \"iteration\",$", MR_Next}, 266a8c51b3fSopenharmony_ci {"\"repetitions\": 1,$", MR_Next}, 267a8c51b3fSopenharmony_ci {"\"repetition_index\": 0,$", MR_Next}, 268a8c51b3fSopenharmony_ci {"\"threads\": 1,$", MR_Next}, 269a8c51b3fSopenharmony_ci {"\"iterations\": %int,$", MR_Next}, 270a8c51b3fSopenharmony_ci {"\"real_time\": %float,$", MR_Next}, 271a8c51b3fSopenharmony_ci {"\"cpu_time\": %float,$", MR_Next}, 272a8c51b3fSopenharmony_ci {"\"time_unit\": \"ns\",$", MR_Next}, 273a8c51b3fSopenharmony_ci {"\"bar\": %float,$", MR_Next}, 274a8c51b3fSopenharmony_ci {"\"foo\": %float$", MR_Next}, 275a8c51b3fSopenharmony_ci {"}", MR_Next}}); 276a8c51b3fSopenharmony_ciADD_CASES( 277a8c51b3fSopenharmony_ci TC_CSVOut, 278a8c51b3fSopenharmony_ci {{"^\"BM_Counters_Threads/threads:%int\",%csv_report,%float,%float$"}}); 279a8c51b3fSopenharmony_ci// VS2013 does not allow this function to be passed as a lambda argument 280a8c51b3fSopenharmony_ci// to CHECK_BENCHMARK_RESULTS() 281a8c51b3fSopenharmony_civoid CheckThreads(Results const& e) { 282a8c51b3fSopenharmony_ci CHECK_COUNTER_VALUE(e, int, "foo", EQ, e.NumThreads()); 283a8c51b3fSopenharmony_ci CHECK_COUNTER_VALUE(e, int, "bar", EQ, 2 * e.NumThreads()); 284a8c51b3fSopenharmony_ci} 285a8c51b3fSopenharmony_ciCHECK_BENCHMARK_RESULTS("BM_Counters_Threads/threads:%int", &CheckThreads); 286a8c51b3fSopenharmony_ci 287a8c51b3fSopenharmony_ci// ========================================================================= // 288a8c51b3fSopenharmony_ci// ---------------------- ThreadAvg Counters Output ------------------------ // 289a8c51b3fSopenharmony_ci// ========================================================================= // 290a8c51b3fSopenharmony_ci 291a8c51b3fSopenharmony_civoid BM_Counters_AvgThreads(benchmark::State& state) { 292a8c51b3fSopenharmony_ci for (auto _ : state) { 293a8c51b3fSopenharmony_ci } 294a8c51b3fSopenharmony_ci namespace bm = benchmark; 295a8c51b3fSopenharmony_ci state.counters["foo"] = bm::Counter{1, bm::Counter::kAvgThreads}; 296a8c51b3fSopenharmony_ci state.counters["bar"] = bm::Counter{2, bm::Counter::kAvgThreads}; 297a8c51b3fSopenharmony_ci} 298a8c51b3fSopenharmony_ciBENCHMARK(BM_Counters_AvgThreads)->ThreadRange(1, 8); 299a8c51b3fSopenharmony_ciADD_CASES(TC_ConsoleOut, {{"^BM_Counters_AvgThreads/threads:%int " 300a8c51b3fSopenharmony_ci "%console_report bar=%hrfloat foo=%hrfloat$"}}); 301a8c51b3fSopenharmony_ciADD_CASES(TC_JSONOut, 302a8c51b3fSopenharmony_ci {{"\"name\": \"BM_Counters_AvgThreads/threads:%int\",$"}, 303a8c51b3fSopenharmony_ci {"\"family_index\": 6,$", MR_Next}, 304a8c51b3fSopenharmony_ci {"\"per_family_instance_index\": 0,$", MR_Next}, 305a8c51b3fSopenharmony_ci {"\"run_name\": \"BM_Counters_AvgThreads/threads:%int\",$", MR_Next}, 306a8c51b3fSopenharmony_ci {"\"run_type\": \"iteration\",$", MR_Next}, 307a8c51b3fSopenharmony_ci {"\"repetitions\": 1,$", MR_Next}, 308a8c51b3fSopenharmony_ci {"\"repetition_index\": 0,$", MR_Next}, 309a8c51b3fSopenharmony_ci {"\"threads\": 1,$", MR_Next}, 310a8c51b3fSopenharmony_ci {"\"iterations\": %int,$", MR_Next}, 311a8c51b3fSopenharmony_ci {"\"real_time\": %float,$", MR_Next}, 312a8c51b3fSopenharmony_ci {"\"cpu_time\": %float,$", MR_Next}, 313a8c51b3fSopenharmony_ci {"\"time_unit\": \"ns\",$", MR_Next}, 314a8c51b3fSopenharmony_ci {"\"bar\": %float,$", MR_Next}, 315a8c51b3fSopenharmony_ci {"\"foo\": %float$", MR_Next}, 316a8c51b3fSopenharmony_ci {"}", MR_Next}}); 317a8c51b3fSopenharmony_ciADD_CASES( 318a8c51b3fSopenharmony_ci TC_CSVOut, 319a8c51b3fSopenharmony_ci {{"^\"BM_Counters_AvgThreads/threads:%int\",%csv_report,%float,%float$"}}); 320a8c51b3fSopenharmony_ci// VS2013 does not allow this function to be passed as a lambda argument 321a8c51b3fSopenharmony_ci// to CHECK_BENCHMARK_RESULTS() 322a8c51b3fSopenharmony_civoid CheckAvgThreads(Results const& e) { 323a8c51b3fSopenharmony_ci CHECK_COUNTER_VALUE(e, int, "foo", EQ, 1); 324a8c51b3fSopenharmony_ci CHECK_COUNTER_VALUE(e, int, "bar", EQ, 2); 325a8c51b3fSopenharmony_ci} 326a8c51b3fSopenharmony_ciCHECK_BENCHMARK_RESULTS("BM_Counters_AvgThreads/threads:%int", 327a8c51b3fSopenharmony_ci &CheckAvgThreads); 328a8c51b3fSopenharmony_ci 329a8c51b3fSopenharmony_ci// ========================================================================= // 330a8c51b3fSopenharmony_ci// ---------------------- ThreadAvg Counters Output ------------------------ // 331a8c51b3fSopenharmony_ci// ========================================================================= // 332a8c51b3fSopenharmony_ci 333a8c51b3fSopenharmony_civoid BM_Counters_AvgThreadsRate(benchmark::State& state) { 334a8c51b3fSopenharmony_ci for (auto _ : state) { 335a8c51b3fSopenharmony_ci // This test requires a non-zero CPU time to avoid divide-by-zero 336a8c51b3fSopenharmony_ci auto iterations = state.iterations(); 337a8c51b3fSopenharmony_ci benchmark::DoNotOptimize(iterations); 338a8c51b3fSopenharmony_ci } 339a8c51b3fSopenharmony_ci namespace bm = benchmark; 340a8c51b3fSopenharmony_ci state.counters["foo"] = bm::Counter{1, bm::Counter::kAvgThreadsRate}; 341a8c51b3fSopenharmony_ci state.counters["bar"] = bm::Counter{2, bm::Counter::kAvgThreadsRate}; 342a8c51b3fSopenharmony_ci} 343a8c51b3fSopenharmony_ciBENCHMARK(BM_Counters_AvgThreadsRate)->ThreadRange(1, 8); 344a8c51b3fSopenharmony_ciADD_CASES(TC_ConsoleOut, {{"^BM_Counters_AvgThreadsRate/threads:%int " 345a8c51b3fSopenharmony_ci "%console_report bar=%hrfloat/s foo=%hrfloat/s$"}}); 346a8c51b3fSopenharmony_ciADD_CASES(TC_JSONOut, 347a8c51b3fSopenharmony_ci {{"\"name\": \"BM_Counters_AvgThreadsRate/threads:%int\",$"}, 348a8c51b3fSopenharmony_ci {"\"family_index\": 7,$", MR_Next}, 349a8c51b3fSopenharmony_ci {"\"per_family_instance_index\": 0,$", MR_Next}, 350a8c51b3fSopenharmony_ci {"\"run_name\": \"BM_Counters_AvgThreadsRate/threads:%int\",$", 351a8c51b3fSopenharmony_ci MR_Next}, 352a8c51b3fSopenharmony_ci {"\"run_type\": \"iteration\",$", MR_Next}, 353a8c51b3fSopenharmony_ci {"\"repetitions\": 1,$", MR_Next}, 354a8c51b3fSopenharmony_ci {"\"repetition_index\": 0,$", MR_Next}, 355a8c51b3fSopenharmony_ci {"\"threads\": 1,$", MR_Next}, 356a8c51b3fSopenharmony_ci {"\"iterations\": %int,$", MR_Next}, 357a8c51b3fSopenharmony_ci {"\"real_time\": %float,$", MR_Next}, 358a8c51b3fSopenharmony_ci {"\"cpu_time\": %float,$", MR_Next}, 359a8c51b3fSopenharmony_ci {"\"time_unit\": \"ns\",$", MR_Next}, 360a8c51b3fSopenharmony_ci {"\"bar\": %float,$", MR_Next}, 361a8c51b3fSopenharmony_ci {"\"foo\": %float$", MR_Next}, 362a8c51b3fSopenharmony_ci {"}", MR_Next}}); 363a8c51b3fSopenharmony_ciADD_CASES(TC_CSVOut, {{"^\"BM_Counters_AvgThreadsRate/" 364a8c51b3fSopenharmony_ci "threads:%int\",%csv_report,%float,%float$"}}); 365a8c51b3fSopenharmony_ci// VS2013 does not allow this function to be passed as a lambda argument 366a8c51b3fSopenharmony_ci// to CHECK_BENCHMARK_RESULTS() 367a8c51b3fSopenharmony_civoid CheckAvgThreadsRate(Results const& e) { 368a8c51b3fSopenharmony_ci CHECK_FLOAT_COUNTER_VALUE(e, "foo", EQ, 1. / e.DurationCPUTime(), 0.001); 369a8c51b3fSopenharmony_ci CHECK_FLOAT_COUNTER_VALUE(e, "bar", EQ, 2. / e.DurationCPUTime(), 0.001); 370a8c51b3fSopenharmony_ci} 371a8c51b3fSopenharmony_ciCHECK_BENCHMARK_RESULTS("BM_Counters_AvgThreadsRate/threads:%int", 372a8c51b3fSopenharmony_ci &CheckAvgThreadsRate); 373a8c51b3fSopenharmony_ci 374a8c51b3fSopenharmony_ci// ========================================================================= // 375a8c51b3fSopenharmony_ci// ------------------- IterationInvariant Counters Output ------------------ // 376a8c51b3fSopenharmony_ci// ========================================================================= // 377a8c51b3fSopenharmony_ci 378a8c51b3fSopenharmony_civoid BM_Counters_IterationInvariant(benchmark::State& state) { 379a8c51b3fSopenharmony_ci for (auto _ : state) { 380a8c51b3fSopenharmony_ci } 381a8c51b3fSopenharmony_ci namespace bm = benchmark; 382a8c51b3fSopenharmony_ci state.counters["foo"] = bm::Counter{1, bm::Counter::kIsIterationInvariant}; 383a8c51b3fSopenharmony_ci state.counters["bar"] = bm::Counter{2, bm::Counter::kIsIterationInvariant}; 384a8c51b3fSopenharmony_ci} 385a8c51b3fSopenharmony_ciBENCHMARK(BM_Counters_IterationInvariant); 386a8c51b3fSopenharmony_ciADD_CASES(TC_ConsoleOut, {{"^BM_Counters_IterationInvariant %console_report " 387a8c51b3fSopenharmony_ci "bar=%hrfloat foo=%hrfloat$"}}); 388a8c51b3fSopenharmony_ciADD_CASES(TC_JSONOut, 389a8c51b3fSopenharmony_ci {{"\"name\": \"BM_Counters_IterationInvariant\",$"}, 390a8c51b3fSopenharmony_ci {"\"family_index\": 8,$", MR_Next}, 391a8c51b3fSopenharmony_ci {"\"per_family_instance_index\": 0,$", MR_Next}, 392a8c51b3fSopenharmony_ci {"\"run_name\": \"BM_Counters_IterationInvariant\",$", MR_Next}, 393a8c51b3fSopenharmony_ci {"\"run_type\": \"iteration\",$", MR_Next}, 394a8c51b3fSopenharmony_ci {"\"repetitions\": 1,$", MR_Next}, 395a8c51b3fSopenharmony_ci {"\"repetition_index\": 0,$", MR_Next}, 396a8c51b3fSopenharmony_ci {"\"threads\": 1,$", MR_Next}, 397a8c51b3fSopenharmony_ci {"\"iterations\": %int,$", MR_Next}, 398a8c51b3fSopenharmony_ci {"\"real_time\": %float,$", MR_Next}, 399a8c51b3fSopenharmony_ci {"\"cpu_time\": %float,$", MR_Next}, 400a8c51b3fSopenharmony_ci {"\"time_unit\": \"ns\",$", MR_Next}, 401a8c51b3fSopenharmony_ci {"\"bar\": %float,$", MR_Next}, 402a8c51b3fSopenharmony_ci {"\"foo\": %float$", MR_Next}, 403a8c51b3fSopenharmony_ci {"}", MR_Next}}); 404a8c51b3fSopenharmony_ciADD_CASES(TC_CSVOut, 405a8c51b3fSopenharmony_ci {{"^\"BM_Counters_IterationInvariant\",%csv_report,%float,%float$"}}); 406a8c51b3fSopenharmony_ci// VS2013 does not allow this function to be passed as a lambda argument 407a8c51b3fSopenharmony_ci// to CHECK_BENCHMARK_RESULTS() 408a8c51b3fSopenharmony_civoid CheckIterationInvariant(Results const& e) { 409a8c51b3fSopenharmony_ci double its = e.NumIterations(); 410a8c51b3fSopenharmony_ci // check that the values are within 0.1% of the expected value 411a8c51b3fSopenharmony_ci CHECK_FLOAT_COUNTER_VALUE(e, "foo", EQ, its, 0.001); 412a8c51b3fSopenharmony_ci CHECK_FLOAT_COUNTER_VALUE(e, "bar", EQ, 2. * its, 0.001); 413a8c51b3fSopenharmony_ci} 414a8c51b3fSopenharmony_ciCHECK_BENCHMARK_RESULTS("BM_Counters_IterationInvariant", 415a8c51b3fSopenharmony_ci &CheckIterationInvariant); 416a8c51b3fSopenharmony_ci 417a8c51b3fSopenharmony_ci// ========================================================================= // 418a8c51b3fSopenharmony_ci// ----------------- IterationInvariantRate Counters Output ---------------- // 419a8c51b3fSopenharmony_ci// ========================================================================= // 420a8c51b3fSopenharmony_ci 421a8c51b3fSopenharmony_civoid BM_Counters_kIsIterationInvariantRate(benchmark::State& state) { 422a8c51b3fSopenharmony_ci for (auto _ : state) { 423a8c51b3fSopenharmony_ci // This test requires a non-zero CPU time to avoid divide-by-zero 424a8c51b3fSopenharmony_ci auto iterations = state.iterations(); 425a8c51b3fSopenharmony_ci benchmark::DoNotOptimize(iterations); 426a8c51b3fSopenharmony_ci } 427a8c51b3fSopenharmony_ci namespace bm = benchmark; 428a8c51b3fSopenharmony_ci state.counters["foo"] = 429a8c51b3fSopenharmony_ci bm::Counter{1, bm::Counter::kIsIterationInvariantRate}; 430a8c51b3fSopenharmony_ci state.counters["bar"] = 431a8c51b3fSopenharmony_ci bm::Counter{2, bm::Counter::kIsRate | bm::Counter::kIsIterationInvariant}; 432a8c51b3fSopenharmony_ci} 433a8c51b3fSopenharmony_ciBENCHMARK(BM_Counters_kIsIterationInvariantRate); 434a8c51b3fSopenharmony_ciADD_CASES(TC_ConsoleOut, {{"^BM_Counters_kIsIterationInvariantRate " 435a8c51b3fSopenharmony_ci "%console_report bar=%hrfloat/s foo=%hrfloat/s$"}}); 436a8c51b3fSopenharmony_ciADD_CASES(TC_JSONOut, 437a8c51b3fSopenharmony_ci {{"\"name\": \"BM_Counters_kIsIterationInvariantRate\",$"}, 438a8c51b3fSopenharmony_ci {"\"family_index\": 9,$", MR_Next}, 439a8c51b3fSopenharmony_ci {"\"per_family_instance_index\": 0,$", MR_Next}, 440a8c51b3fSopenharmony_ci {"\"run_name\": \"BM_Counters_kIsIterationInvariantRate\",$", 441a8c51b3fSopenharmony_ci MR_Next}, 442a8c51b3fSopenharmony_ci {"\"run_type\": \"iteration\",$", MR_Next}, 443a8c51b3fSopenharmony_ci {"\"repetitions\": 1,$", MR_Next}, 444a8c51b3fSopenharmony_ci {"\"repetition_index\": 0,$", MR_Next}, 445a8c51b3fSopenharmony_ci {"\"threads\": 1,$", MR_Next}, 446a8c51b3fSopenharmony_ci {"\"iterations\": %int,$", MR_Next}, 447a8c51b3fSopenharmony_ci {"\"real_time\": %float,$", MR_Next}, 448a8c51b3fSopenharmony_ci {"\"cpu_time\": %float,$", MR_Next}, 449a8c51b3fSopenharmony_ci {"\"time_unit\": \"ns\",$", MR_Next}, 450a8c51b3fSopenharmony_ci {"\"bar\": %float,$", MR_Next}, 451a8c51b3fSopenharmony_ci {"\"foo\": %float$", MR_Next}, 452a8c51b3fSopenharmony_ci {"}", MR_Next}}); 453a8c51b3fSopenharmony_ciADD_CASES(TC_CSVOut, {{"^\"BM_Counters_kIsIterationInvariantRate\",%csv_report," 454a8c51b3fSopenharmony_ci "%float,%float$"}}); 455a8c51b3fSopenharmony_ci// VS2013 does not allow this function to be passed as a lambda argument 456a8c51b3fSopenharmony_ci// to CHECK_BENCHMARK_RESULTS() 457a8c51b3fSopenharmony_civoid CheckIsIterationInvariantRate(Results const& e) { 458a8c51b3fSopenharmony_ci double its = e.NumIterations(); 459a8c51b3fSopenharmony_ci double t = e.DurationCPUTime(); // this (and not real time) is the time used 460a8c51b3fSopenharmony_ci // check that the values are within 0.1% of the expected values 461a8c51b3fSopenharmony_ci CHECK_FLOAT_COUNTER_VALUE(e, "foo", EQ, its * 1. / t, 0.001); 462a8c51b3fSopenharmony_ci CHECK_FLOAT_COUNTER_VALUE(e, "bar", EQ, its * 2. / t, 0.001); 463a8c51b3fSopenharmony_ci} 464a8c51b3fSopenharmony_ciCHECK_BENCHMARK_RESULTS("BM_Counters_kIsIterationInvariantRate", 465a8c51b3fSopenharmony_ci &CheckIsIterationInvariantRate); 466a8c51b3fSopenharmony_ci 467a8c51b3fSopenharmony_ci// ========================================================================= // 468a8c51b3fSopenharmony_ci// --------------------- AvgIterations Counters Output --------------------- // 469a8c51b3fSopenharmony_ci// ========================================================================= // 470a8c51b3fSopenharmony_ci 471a8c51b3fSopenharmony_civoid BM_Counters_AvgIterations(benchmark::State& state) { 472a8c51b3fSopenharmony_ci for (auto _ : state) { 473a8c51b3fSopenharmony_ci } 474a8c51b3fSopenharmony_ci namespace bm = benchmark; 475a8c51b3fSopenharmony_ci state.counters["foo"] = bm::Counter{1, bm::Counter::kAvgIterations}; 476a8c51b3fSopenharmony_ci state.counters["bar"] = bm::Counter{2, bm::Counter::kAvgIterations}; 477a8c51b3fSopenharmony_ci} 478a8c51b3fSopenharmony_ciBENCHMARK(BM_Counters_AvgIterations); 479a8c51b3fSopenharmony_ciADD_CASES(TC_ConsoleOut, {{"^BM_Counters_AvgIterations %console_report " 480a8c51b3fSopenharmony_ci "bar=%hrfloat foo=%hrfloat$"}}); 481a8c51b3fSopenharmony_ciADD_CASES(TC_JSONOut, 482a8c51b3fSopenharmony_ci {{"\"name\": \"BM_Counters_AvgIterations\",$"}, 483a8c51b3fSopenharmony_ci {"\"family_index\": 10,$", MR_Next}, 484a8c51b3fSopenharmony_ci {"\"per_family_instance_index\": 0,$", MR_Next}, 485a8c51b3fSopenharmony_ci {"\"run_name\": \"BM_Counters_AvgIterations\",$", MR_Next}, 486a8c51b3fSopenharmony_ci {"\"run_type\": \"iteration\",$", MR_Next}, 487a8c51b3fSopenharmony_ci {"\"repetitions\": 1,$", MR_Next}, 488a8c51b3fSopenharmony_ci {"\"repetition_index\": 0,$", MR_Next}, 489a8c51b3fSopenharmony_ci {"\"threads\": 1,$", MR_Next}, 490a8c51b3fSopenharmony_ci {"\"iterations\": %int,$", MR_Next}, 491a8c51b3fSopenharmony_ci {"\"real_time\": %float,$", MR_Next}, 492a8c51b3fSopenharmony_ci {"\"cpu_time\": %float,$", MR_Next}, 493a8c51b3fSopenharmony_ci {"\"time_unit\": \"ns\",$", MR_Next}, 494a8c51b3fSopenharmony_ci {"\"bar\": %float,$", MR_Next}, 495a8c51b3fSopenharmony_ci {"\"foo\": %float$", MR_Next}, 496a8c51b3fSopenharmony_ci {"}", MR_Next}}); 497a8c51b3fSopenharmony_ciADD_CASES(TC_CSVOut, 498a8c51b3fSopenharmony_ci {{"^\"BM_Counters_AvgIterations\",%csv_report,%float,%float$"}}); 499a8c51b3fSopenharmony_ci// VS2013 does not allow this function to be passed as a lambda argument 500a8c51b3fSopenharmony_ci// to CHECK_BENCHMARK_RESULTS() 501a8c51b3fSopenharmony_civoid CheckAvgIterations(Results const& e) { 502a8c51b3fSopenharmony_ci double its = e.NumIterations(); 503a8c51b3fSopenharmony_ci // check that the values are within 0.1% of the expected value 504a8c51b3fSopenharmony_ci CHECK_FLOAT_COUNTER_VALUE(e, "foo", EQ, 1. / its, 0.001); 505a8c51b3fSopenharmony_ci CHECK_FLOAT_COUNTER_VALUE(e, "bar", EQ, 2. / its, 0.001); 506a8c51b3fSopenharmony_ci} 507a8c51b3fSopenharmony_ciCHECK_BENCHMARK_RESULTS("BM_Counters_AvgIterations", &CheckAvgIterations); 508a8c51b3fSopenharmony_ci 509a8c51b3fSopenharmony_ci// ========================================================================= // 510a8c51b3fSopenharmony_ci// ------------------- AvgIterationsRate Counters Output ------------------- // 511a8c51b3fSopenharmony_ci// ========================================================================= // 512a8c51b3fSopenharmony_ci 513a8c51b3fSopenharmony_civoid BM_Counters_kAvgIterationsRate(benchmark::State& state) { 514a8c51b3fSopenharmony_ci for (auto _ : state) { 515a8c51b3fSopenharmony_ci // This test requires a non-zero CPU time to avoid divide-by-zero 516a8c51b3fSopenharmony_ci auto iterations = state.iterations(); 517a8c51b3fSopenharmony_ci benchmark::DoNotOptimize(iterations); 518a8c51b3fSopenharmony_ci } 519a8c51b3fSopenharmony_ci namespace bm = benchmark; 520a8c51b3fSopenharmony_ci state.counters["foo"] = bm::Counter{1, bm::Counter::kAvgIterationsRate}; 521a8c51b3fSopenharmony_ci state.counters["bar"] = 522a8c51b3fSopenharmony_ci bm::Counter{2, bm::Counter::kIsRate | bm::Counter::kAvgIterations}; 523a8c51b3fSopenharmony_ci} 524a8c51b3fSopenharmony_ciBENCHMARK(BM_Counters_kAvgIterationsRate); 525a8c51b3fSopenharmony_ciADD_CASES(TC_ConsoleOut, {{"^BM_Counters_kAvgIterationsRate " 526a8c51b3fSopenharmony_ci "%console_report bar=%hrfloat/s foo=%hrfloat/s$"}}); 527a8c51b3fSopenharmony_ciADD_CASES(TC_JSONOut, 528a8c51b3fSopenharmony_ci {{"\"name\": \"BM_Counters_kAvgIterationsRate\",$"}, 529a8c51b3fSopenharmony_ci {"\"family_index\": 11,$", MR_Next}, 530a8c51b3fSopenharmony_ci {"\"per_family_instance_index\": 0,$", MR_Next}, 531a8c51b3fSopenharmony_ci {"\"run_name\": \"BM_Counters_kAvgIterationsRate\",$", MR_Next}, 532a8c51b3fSopenharmony_ci {"\"run_type\": \"iteration\",$", MR_Next}, 533a8c51b3fSopenharmony_ci {"\"repetitions\": 1,$", MR_Next}, 534a8c51b3fSopenharmony_ci {"\"repetition_index\": 0,$", MR_Next}, 535a8c51b3fSopenharmony_ci {"\"threads\": 1,$", MR_Next}, 536a8c51b3fSopenharmony_ci {"\"iterations\": %int,$", MR_Next}, 537a8c51b3fSopenharmony_ci {"\"real_time\": %float,$", MR_Next}, 538a8c51b3fSopenharmony_ci {"\"cpu_time\": %float,$", MR_Next}, 539a8c51b3fSopenharmony_ci {"\"time_unit\": \"ns\",$", MR_Next}, 540a8c51b3fSopenharmony_ci {"\"bar\": %float,$", MR_Next}, 541a8c51b3fSopenharmony_ci {"\"foo\": %float$", MR_Next}, 542a8c51b3fSopenharmony_ci {"}", MR_Next}}); 543a8c51b3fSopenharmony_ciADD_CASES(TC_CSVOut, {{"^\"BM_Counters_kAvgIterationsRate\",%csv_report," 544a8c51b3fSopenharmony_ci "%float,%float$"}}); 545a8c51b3fSopenharmony_ci// VS2013 does not allow this function to be passed as a lambda argument 546a8c51b3fSopenharmony_ci// to CHECK_BENCHMARK_RESULTS() 547a8c51b3fSopenharmony_civoid CheckAvgIterationsRate(Results const& e) { 548a8c51b3fSopenharmony_ci double its = e.NumIterations(); 549a8c51b3fSopenharmony_ci double t = e.DurationCPUTime(); // this (and not real time) is the time used 550a8c51b3fSopenharmony_ci // check that the values are within 0.1% of the expected values 551a8c51b3fSopenharmony_ci CHECK_FLOAT_COUNTER_VALUE(e, "foo", EQ, 1. / its / t, 0.001); 552a8c51b3fSopenharmony_ci CHECK_FLOAT_COUNTER_VALUE(e, "bar", EQ, 2. / its / t, 0.001); 553a8c51b3fSopenharmony_ci} 554a8c51b3fSopenharmony_ciCHECK_BENCHMARK_RESULTS("BM_Counters_kAvgIterationsRate", 555a8c51b3fSopenharmony_ci &CheckAvgIterationsRate); 556a8c51b3fSopenharmony_ci 557a8c51b3fSopenharmony_ci// ========================================================================= // 558a8c51b3fSopenharmony_ci// --------------------------- TEST CASES END ------------------------------ // 559a8c51b3fSopenharmony_ci// ========================================================================= // 560a8c51b3fSopenharmony_ci 561a8c51b3fSopenharmony_ciint main(int argc, char* argv[]) { RunOutputTests(argc, argv); } 562