|
| 1 | + |
| 2 | +#undef NDEBUG |
| 3 | + |
| 4 | +#include "benchmark/benchmark.h" |
| 5 | +#include "output_test.h" |
| 6 | + |
| 7 | +// ========================================================================= // |
| 8 | +// ------------------------ Thousands Customisation ------------------------ // |
| 9 | +// ========================================================================= // |
| 10 | + |
| 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", |
| 19 | + bm::Counter(1000 * 1000, bm::Counter::kDefaults, 1000)}, |
| 20 | + {"t2_1000000Base1024", |
| 21 | + bm::Counter(1000 * 1000, bm::Counter::kDefaults, 1024)}, |
| 22 | + {"t3_1048576Base1000", |
| 23 | + bm::Counter(1024 * 1024, bm::Counter::kDefaults, 1000)}, |
| 24 | + {"t4_1048576Base1024", |
| 25 | + bm::Counter(1024 * 1024, bm::Counter::kDefaults, 1024)}}); |
| 26 | +} |
| 27 | +BENCHMARK(BM_Counters_Thousands)->Repetitions(2); |
| 28 | +ADD_CASES( |
| 29 | + TC_ConsoleOut, |
| 30 | + { |
| 31 | + {"^BM_Counters_Thousands/repeats:2 %console_report " |
| 32 | + "t0_1000000DefaultBase=1000k " |
| 33 | + "t1_1000000Base1000=1000k t2_1000000Base1024=976.56[23]k " |
| 34 | + "t3_1048576Base1000=1048.58k t4_1048576Base1024=1024k$"}, |
| 35 | + {"^BM_Counters_Thousands/repeats:2 %console_report " |
| 36 | + "t0_1000000DefaultBase=1000k " |
| 37 | + "t1_1000000Base1000=1000k t2_1000000Base1024=976.56[23]k " |
| 38 | + "t3_1048576Base1000=1048.58k t4_1048576Base1024=1024k$"}, |
| 39 | + {"^BM_Counters_Thousands/repeats:2_mean %console_report " |
| 40 | + "t0_1000000DefaultBase=1000k t1_1000000Base1000=1000k " |
| 41 | + "t2_1000000Base1024=976.56[23]k t3_1048576Base1000=1048.58k " |
| 42 | + "t4_1048576Base1024=1024k$"}, |
| 43 | + {"^BM_Counters_Thousands/repeats:2_median %console_report " |
| 44 | + "t0_1000000DefaultBase=1000k t1_1000000Base1000=1000k " |
| 45 | + "t2_1000000Base1024=976.56[23]k t3_1048576Base1000=1048.58k " |
| 46 | + "t4_1048576Base1024=1024k$"}, |
| 47 | + {"^BM_Counters_Thousands/repeats:2_stddev %console_report " |
| 48 | + "t0_1000000DefaultBase=0 t1_1000000Base1000=0 t2_1000000Base1024=0 " |
| 49 | + "t3_1048576Base1000=0 t4_1048576Base1024=0$"}, |
| 50 | + }); |
| 51 | +ADD_CASES(TC_JSONOut, |
| 52 | + {{"\"name\": \"BM_Counters_Thousands/repeats:2\",$"}, |
| 53 | + {"\"iterations\": %int,$", MR_Next}, |
| 54 | + {"\"real_time\": %float,$", MR_Next}, |
| 55 | + {"\"cpu_time\": %float,$", MR_Next}, |
| 56 | + {"\"time_unit\": \"ns\",$", MR_Next}, |
| 57 | + {"\"t0_1000000DefaultBase\": 1\\.(0)*e\\+(0)*6,$", MR_Next}, |
| 58 | + {"\"t1_1000000Base1000\": 1\\.(0)*e\\+(0)*6,$", MR_Next}, |
| 59 | + {"\"t2_1000000Base1024\": 1\\.(0)*e\\+(0)*6,$", MR_Next}, |
| 60 | + {"\"t3_1048576Base1000\": 1\\.048576(0)*e\\+(0)*6,$", MR_Next}, |
| 61 | + {"\"t4_1048576Base1024\": 1\\.048576(0)*e\\+(0)*6$", MR_Next}, |
| 62 | + {"}", MR_Next}}); |
| 63 | +ADD_CASES(TC_JSONOut, |
| 64 | + {{"\"name\": \"BM_Counters_Thousands/repeats:2\",$"}, |
| 65 | + {"\"iterations\": %int,$", MR_Next}, |
| 66 | + {"\"real_time\": %float,$", MR_Next}, |
| 67 | + {"\"cpu_time\": %float,$", MR_Next}, |
| 68 | + {"\"time_unit\": \"ns\",$", MR_Next}, |
| 69 | + {"\"t0_1000000DefaultBase\": 1\\.(0)*e\\+(0)*6,$", MR_Next}, |
| 70 | + {"\"t1_1000000Base1000\": 1\\.(0)*e\\+(0)*6,$", MR_Next}, |
| 71 | + {"\"t2_1000000Base1024\": 1\\.(0)*e\\+(0)*6,$", MR_Next}, |
| 72 | + {"\"t3_1048576Base1000\": 1\\.048576(0)*e\\+(0)*6,$", MR_Next}, |
| 73 | + {"\"t4_1048576Base1024\": 1\\.048576(0)*e\\+(0)*6$", MR_Next}, |
| 74 | + {"}", MR_Next}}); |
| 75 | +ADD_CASES(TC_JSONOut, |
| 76 | + {{"\"name\": \"BM_Counters_Thousands/repeats:2_mean\",$"}, |
| 77 | + {"\"iterations\": %int,$", MR_Next}, |
| 78 | + {"\"real_time\": %float,$", MR_Next}, |
| 79 | + {"\"cpu_time\": %float,$", MR_Next}, |
| 80 | + {"\"time_unit\": \"ns\",$", MR_Next}, |
| 81 | + {"\"t0_1000000DefaultBase\": 1\\.(0)*e\\+(0)*6,$", MR_Next}, |
| 82 | + {"\"t1_1000000Base1000\": 1\\.(0)*e\\+(0)*6,$", MR_Next}, |
| 83 | + {"\"t2_1000000Base1024\": 1\\.(0)*e\\+(0)*6,$", MR_Next}, |
| 84 | + {"\"t3_1048576Base1000\": 1\\.048576(0)*e\\+(0)*6,$", MR_Next}, |
| 85 | + {"\"t4_1048576Base1024\": 1\\.048576(0)*e\\+(0)*6$", MR_Next}, |
| 86 | + {"}", MR_Next}}); |
| 87 | +ADD_CASES(TC_JSONOut, |
| 88 | + {{"\"name\": \"BM_Counters_Thousands/repeats:2_median\",$"}, |
| 89 | + {"\"iterations\": %int,$", MR_Next}, |
| 90 | + {"\"real_time\": %float,$", MR_Next}, |
| 91 | + {"\"cpu_time\": %float,$", MR_Next}, |
| 92 | + {"\"time_unit\": \"ns\",$", MR_Next}, |
| 93 | + {"\"t0_1000000DefaultBase\": 1\\.(0)*e\\+(0)*6,$", MR_Next}, |
| 94 | + {"\"t1_1000000Base1000\": 1\\.(0)*e\\+(0)*6,$", MR_Next}, |
| 95 | + {"\"t2_1000000Base1024\": 1\\.(0)*e\\+(0)*6,$", MR_Next}, |
| 96 | + {"\"t3_1048576Base1000\": 1\\.048576(0)*e\\+(0)*6,$", MR_Next}, |
| 97 | + {"\"t4_1048576Base1024\": 1\\.048576(0)*e\\+(0)*6$", MR_Next}, |
| 98 | + {"}", MR_Next}}); |
| 99 | +ADD_CASES(TC_JSONOut, |
| 100 | + {{"\"name\": \"BM_Counters_Thousands/repeats:2_stddev\",$"}, |
| 101 | + {"\"iterations\": %int,$", MR_Next}, |
| 102 | + {"\"real_time\": %float,$", MR_Next}, |
| 103 | + {"\"cpu_time\": %float,$", MR_Next}, |
| 104 | + {"\"time_unit\": \"ns\",$", MR_Next}, |
| 105 | + {"\"t0_1000000DefaultBase\": 0\\.(0)*e\\+(0)*,$", MR_Next}, |
| 106 | + {"\"t1_1000000Base1000\": 0\\.(0)*e\\+(0)*,$", MR_Next}, |
| 107 | + {"\"t2_1000000Base1024\": 0\\.(0)*e\\+(0)*,$", MR_Next}, |
| 108 | + {"\"t3_1048576Base1000\": 0\\.(0)*e\\+(0)*,$", MR_Next}, |
| 109 | + {"\"t4_1048576Base1024\": 0\\.(0)*e\\+(0)*$", MR_Next}, |
| 110 | + {"}", MR_Next}}); |
| 111 | + |
| 112 | +ADD_CASES( |
| 113 | + TC_CSVOut, |
| 114 | + {{"^\"BM_Counters_Thousands/repeats:2\",%csv_report,1e\\+06,1e\\+06," |
| 115 | + "1e\\+06,1\\.04858e\\+06,1\\.04858e\\+06$"}, |
| 116 | + {"^\"BM_Counters_Thousands/repeats:2\",%csv_report,1e\\+06,1e\\+06," |
| 117 | + "1e\\+06,1\\.04858e\\+06,1\\.04858e\\+06$"}, |
| 118 | + {"^\"BM_Counters_Thousands/" |
| 119 | + "repeats:2_mean\",%csv_report,1e\\+06,1e\\+06,1e\\+06,1\\.04858e\\+06," |
| 120 | + "1\\.04858e\\+06$"}, |
| 121 | + {"^\"BM_Counters_Thousands/" |
| 122 | + "repeats:2_median\",%csv_report,1e\\+06,1e\\+06,1e\\+06,1\\.04858e\\+" |
| 123 | + "06,1\\.04858e\\+06$"}, |
| 124 | + {"^\"BM_Counters_Thousands/repeats:2_stddev\",%csv_report,0,0,0,0,0$"}}); |
| 125 | +// VS2013 does not allow this function to be passed as a lambda argument |
| 126 | +// to CHECK_BENCHMARK_RESULTS() |
| 127 | +void CheckThousands(Results const& e) { |
| 128 | + if (e.name != "BM_Counters_Thousands/repeats:2") |
| 129 | + return; // Do not check the aggregates! |
| 130 | + |
| 131 | + // check that the values are within 0.01% of the expected values |
| 132 | + CHECK_FLOAT_COUNTER_VALUE(e, "t0_1000000DefaultBase", EQ, 1000 * 1000, |
| 133 | + 0.0001); |
| 134 | + CHECK_FLOAT_COUNTER_VALUE(e, "t1_1000000Base1000", EQ, 1000 * 1000, 0.0001); |
| 135 | + CHECK_FLOAT_COUNTER_VALUE(e, "t2_1000000Base1024", EQ, 1000 * 1000, 0.0001); |
| 136 | + CHECK_FLOAT_COUNTER_VALUE(e, "t3_1048576Base1000", EQ, 1024 * 1024, 0.0001); |
| 137 | + CHECK_FLOAT_COUNTER_VALUE(e, "t4_1048576Base1024", EQ, 1024 * 1024, 0.0001); |
| 138 | +} |
| 139 | +CHECK_BENCHMARK_RESULTS("BM_Counters_Thousands", &CheckThousands); |
| 140 | + |
| 141 | +// ========================================================================= // |
| 142 | +// --------------------------- TEST CASES END ------------------------------ // |
| 143 | +// ========================================================================= // |
| 144 | + |
| 145 | +int main(int argc, char* argv[]) { RunOutputTests(argc, argv); } |
0 commit comments