Go to the documentation of this file.
4 #include "benchmark/benchmark.h"
13 {
"^Benchmark %s Time %s CPU %s Iterations UserCounters...$",
MR_Next},
22 while (
state.KeepRunning()) {
24 state.counters[
"foo"] = 1;
25 state.counters[
"bar"] = 2 * (double)
state.iterations();
30 {
"\"iterations\": %int,$",
MR_Next},
31 {
"\"real_time\": %int,$",
MR_Next},
32 {
"\"cpu_time\": %int,$",
MR_Next},
33 {
"\"time_unit\": \"ns\",$",
MR_Next},
41 double its = e.GetAs<
double >(
"iterations");
52 namespace {
int num_calls1 = 0; }
54 while (
state.KeepRunning()) {
56 state.counters[
"foo"] = 1;
57 state.counters[
"bar"] = ++num_calls1;
58 state.SetBytesProcessed(364);
59 state.SetItemsProcessed(150);
63 {{
"^BM_Counters_WithBytesAndItemsPSec %console_report "
64 "bar=%hrfloat foo=%hrfloat +%hrfloatB/s +%hrfloat items/s$"}});
66 {
"\"iterations\": %int,$",
MR_Next},
67 {
"\"real_time\": %int,$",
MR_Next},
68 {
"\"cpu_time\": %int,$",
MR_Next},
69 {
"\"time_unit\": \"ns\",$",
MR_Next},
70 {
"\"bytes_per_second\": %int,$",
MR_Next},
71 {
"\"items_per_second\": %int,$",
MR_Next},
76 "%csv_bytes_items_report,%float,%float$"}});
80 double t = e.DurationCPUTime();
95 while (
state.KeepRunning()) {
98 state.counters[
"foo"] = bm::Counter{1, bm::Counter::kIsRate};
99 state.counters[
"bar"] = bm::Counter{2, bm::Counter::kIsRate};
104 {
"\"iterations\": %int,$",
MR_Next},
105 {
"\"real_time\": %int,$",
MR_Next},
106 {
"\"cpu_time\": %int,$",
MR_Next},
107 {
"\"time_unit\": \"ns\",$",
MR_Next},
108 {
"\"bar\": %float,$",
MR_Next},
115 double t = e.DurationCPUTime();
127 while (
state.KeepRunning()) {
129 state.counters[
"foo"] = 1;
130 state.counters[
"bar"] = 2;
133 ADD_CASES(
TC_ConsoleOut, {{
"^BM_Counters_Threads/threads:%int %console_report bar=%hrfloat foo=%hrfloat$"}});
135 {
"\"iterations\": %int,$",
MR_Next},
136 {
"\"real_time\": %int,$",
MR_Next},
137 {
"\"cpu_time\": %int,$",
MR_Next},
138 {
"\"time_unit\": \"ns\",$",
MR_Next},
139 {
"\"bar\": %float,$",
MR_Next},
142 ADD_CASES(
TC_CSVOut, {{
"^\"BM_Counters_Threads/threads:%int\",%csv_report,%float,%float$"}});
156 while (
state.KeepRunning()) {
159 state.counters[
"foo"] = bm::Counter{1, bm::Counter::kAvgThreads};
160 state.counters[
"bar"] = bm::Counter{2, bm::Counter::kAvgThreads};
163 ADD_CASES(
TC_ConsoleOut, {{
"^BM_Counters_AvgThreads/threads:%int %console_report bar=%hrfloat foo=%hrfloat$"}});
165 {
"\"iterations\": %int,$",
MR_Next},
166 {
"\"real_time\": %int,$",
MR_Next},
167 {
"\"cpu_time\": %int,$",
MR_Next},
168 {
"\"time_unit\": \"ns\",$",
MR_Next},
169 {
"\"bar\": %float,$",
MR_Next},
172 ADD_CASES(
TC_CSVOut, {{
"^\"BM_Counters_AvgThreads/threads:%int\",%csv_report,%float,%float$"}});
187 while (
state.KeepRunning()) {
190 state.counters[
"foo"] = bm::Counter{1, bm::Counter::kAvgThreadsRate};
191 state.counters[
"bar"] = bm::Counter{2, bm::Counter::kAvgThreadsRate};
194 ADD_CASES(
TC_ConsoleOut, {{
"^BM_Counters_AvgThreadsRate/threads:%int %console_report bar=%hrfloat/s foo=%hrfloat/s$"}});
196 {
"\"iterations\": %int,$",
MR_Next},
197 {
"\"real_time\": %int,$",
MR_Next},
198 {
"\"cpu_time\": %int,$",
MR_Next},
199 {
"\"time_unit\": \"ns\",$",
MR_Next},
200 {
"\"bar\": %float,$",
MR_Next},
203 ADD_CASES(
TC_CSVOut, {{
"^\"BM_Counters_AvgThreadsRate/threads:%int\",%csv_report,%float,%float$"}});
void BM_Counters_Threads(benchmark::State &state)
BENCHMARK(BM_Counters_Simple)
void CheckAvgThreads(Results const &e)
ADD_CASES(TC_ConsoleOut, {{"^[-]+$", MR_Next}, {"^Benchmark %s Time %s CPU %s Iterations UserCounters...$", MR_Next}, {"^[-]+$", MR_Next}})
void CheckSimple(Results const &e)
void CheckRate(Results const &e)
void BM_Counters_WithBytesAndItemsPSec(benchmark::State &state)
#define CHECK_FLOAT_RESULT_VALUE(entry, var_name, relationship, value, eps_factor)
void BM_Counters_Simple(benchmark::State &state)
void BM_Counters_AvgThreads(benchmark::State &state)
void CheckThreads(Results const &e)
CHECK_BENCHMARK_RESULTS("BM_Counters_Simple", &CheckSimple)
int main(int argc, char *argv[])
void RunOutputTests(int argc, char *argv[])
#define CHECK_FLOAT_COUNTER_VALUE(entry, var_name, relationship, value, eps_factor)
void BM_Counters_AvgThreadsRate(benchmark::State &state)
void CheckAvgThreadsRate(Results const &e)
void CheckBytesAndItemsPSec(Results const &e)
#define CHECK_COUNTER_VALUE(entry, var_type, var_name, relationship, value)
void BM_Counters_Rate(benchmark::State &state)
grpc
Author(s):
autogenerated on Fri May 16 2025 03:00:48