benchmark_main.cc File Reference
#include "benchmark.h"
#include <regex.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <inttypes.h>
#include <time.h>
#include <map>

Namespaces

 testing
 

Typedefs

typedef std::map< std::string, ::testing::Benchmark * > BenchmarkMap
 
typedef BenchmarkMap::iterator BenchmarkMapIt
 

Functions

BenchmarkMapgBenchmarks ()
 
static int Round (int n)
 
static int64_t NanoTime ()
 
void SetBenchmarkFlopsProcessed (int64_t x)
 
void StopBenchmarkTiming ()
 
void StartBenchmarkTiming ()
 
int main (int argc, char *argv[])
 

Variables

static int64_t g_flops_processed
 
static int64_t g_benchmark_total_time_ns
 
static int64_t g_benchmark_start_time_ns
 
static int g_name_column_width = 20
 

Typedef Documentation

◆ BenchmarkMap

typedef std::map<std::string, ::testing::Benchmark*> BenchmarkMap

◆ BenchmarkMapIt

typedef BenchmarkMap::iterator BenchmarkMapIt

Function Documentation

◆ gBenchmarks()

BenchmarkMap& gBenchmarks ( )
32  {
33  static BenchmarkMap g_benchmarks;
34  return g_benchmarks;
35 }
std::map< std::string, ::testing::Benchmark * > BenchmarkMap
Definition: benchmark_main.cc:29

Referenced by main(), and testing::Benchmark::Register().

◆ main()

int main ( int argc  ,
char argv[] 
)
201  {
202  if (gBenchmarks().empty()) {
203  fprintf(stderr, "No benchmarks registered!\n");
204  exit(EXIT_FAILURE);
205  }
206  for (BenchmarkMapIt it = gBenchmarks().begin(); it != gBenchmarks().end(); ++it) {
207  int name_width = static_cast<int>(strlen(it->second->Name()));
209  }
210  bool need_header = true;
211  for (BenchmarkMapIt it = gBenchmarks().begin(); it != gBenchmarks().end(); ++it) {
212  ::testing::Benchmark* b = it->second;
213  if (b->ShouldRun(argc, argv)) {
214  if (need_header) {
215  printf("%-*s %10s %10s\n", g_name_column_width, "", "iterations", "ns/op");
216  fflush(stdout);
217  need_header = false;
218  }
219  b->Run();
220  }
221  }
222  if (need_header) {
223  fprintf(stderr, "No matching benchmarks!\n");
224  fprintf(stderr, "Available benchmarks:\n");
225  for (BenchmarkMapIt it = gBenchmarks().begin(); it != gBenchmarks().end(); ++it) {
226  fprintf(stderr, " %s\n", it->second->Name());
227  }
228  exit(EXIT_FAILURE);
229  }
230  return 0;
231 }
Scalar * b
Definition: benchVecAdd.cpp:17
BenchmarkMap & gBenchmarks()
Definition: benchmark_main.cc:32
static int g_name_column_width
Definition: benchmark_main.cc:37
BenchmarkMap::iterator BenchmarkMapIt
Definition: benchmark_main.cc:30
Definition: benchmark.h:21
#define max(a, b)
Definition: datatypes.h:23
stdout
Definition: fix_broken_doxygen_formulae.py:258

References b, g_name_column_width, gBenchmarks(), max, and fix_broken_doxygen_formulae::stdout.

◆ NanoTime()

static int64_t NanoTime ( )
static
59  {
60 #if defined(__APPLE__)
61  uint64_t t = mach_absolute_time();
62  return t * g_time_info.numer / g_time_info.denom;
63 #else
64  struct timespec t;
65  t.tv_sec = t.tv_nsec = 0;
66  clock_gettime(CLOCK_MONOTONIC, &t);
67  return static_cast<int64_t>(t.tv_sec) * 1000000000LL + t.tv_nsec;
68 #endif
69 }
std::int64_t int64_t
Definition: Meta.h:43
std::uint64_t uint64_t
Definition: Meta.h:42
t
Definition: plotPSD.py:36

References plotPSD::t.

Referenced by testing::Benchmark::RunRepeatedlyWithArg(), StartBenchmarkTiming(), and StopBenchmarkTiming().

◆ Round()

static int Round ( int  n)
static
39  {
40  int base = 1;
41  while (base * 10 < n) {
42  base *= 10;
43  }
44  if (n < 2 * base) {
45  return 2 * base;
46  }
47  if (n < 5 * base) {
48  return 5 * base;
49  }
50  return 10 * base;
51 }
const unsigned n
Definition: CG3DPackingUnitTest.cpp:11

References n.

Referenced by testing::Benchmark::RunWithArg().

◆ SetBenchmarkFlopsProcessed()

void SetBenchmarkFlopsProcessed ( int64_t  x)
189 { g_flops_processed = x; }
static int64_t g_flops_processed
Definition: benchmark_main.cc:26
list x
Definition: plotDoE.py:28

References g_flops_processed, and plotDoE::x.

Referenced by BenchmarkSuite< Device, T >::finalizeBenchmark().

◆ StartBenchmarkTiming()

◆ StopBenchmarkTiming()

void StopBenchmarkTiming ( )
190  {
191  if (g_benchmark_start_time_ns != 0) {
193  }
195 }
static int64_t g_benchmark_total_time_ns
Definition: benchmark_main.cc:27

References g_benchmark_start_time_ns, g_benchmark_total_time_ns, and NanoTime().

Referenced by BenchmarkSuite< Device, T >::finalizeBenchmark().

Variable Documentation

◆ g_benchmark_start_time_ns

int64_t g_benchmark_start_time_ns
static

◆ g_benchmark_total_time_ns

int64_t g_benchmark_total_time_ns
static

◆ g_flops_processed

◆ g_name_column_width

int g_name_column_width = 20
static