DGtal  1.0.0
Macros | Functions
testBenchmark.cpp File Reference
#include <iostream>
#include <string>
#include <sstream>
#include <benchmark/benchmark.h>
Include dependency graph for testBenchmark.cpp:

Go to the source code of this file.

Macros

#define BENCHMARK_NOINLINE
 

Functions

int BENCHMARK_NOINLINE Factorial (uint32_t n)
 
static void BM_StringCreation (benchmark::State &state)
 
 BENCHMARK (BM_StringCreation)
 
static void BM_StringCopy (benchmark::State &state)
 
 BENCHMARK (BM_StringCopy)
 
static void BM_Factorial (benchmark::State &state)
 
 BENCHMARK (BM_Factorial)
 
double CalculatePi (int depth)
 
static void BM_CalculatePiRange (benchmark::State &state)
 
 BENCHMARK_RANGE (BM_CalculatePiRange, 1, 256 *256)
 
static void BM_CalculatePi (benchmark::State &state)
 
 BENCHMARK (BM_CalculatePi) -> Threads(8)
 
static void BM_LongTest (benchmark::State &state)
 
 BENCHMARK (BM_LongTest) -> Range(1<< 4, 1<< 6)
 
int main (int argc, char *argv[])
 

Detailed Description

This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Author
David Coeurjolly (david.nosp@m..coe.nosp@m.urjol.nosp@m.ly@l.nosp@m.iris..nosp@m.cnrs.nosp@m..fr ) Laboratoire d'InfoRmatique en Image et Systemes d'information - LIRIS (CNRS, UMR 5205), CNRS, France
Date
2014/02/26

Functions for testing class Benchmark.

This file is part of the DGtal library.

Definition in file testBenchmark.cpp.

Macro Definition Documentation

◆ BENCHMARK_NOINLINE

#define BENCHMARK_NOINLINE

Definition at line 47 of file testBenchmark.cpp.

Function Documentation

◆ BENCHMARK() [1/5]

BENCHMARK ( BM_StringCreation  )

◆ BENCHMARK() [2/5]

BENCHMARK ( BM_StringCopy  )

◆ BENCHMARK() [3/5]

BENCHMARK ( BM_Factorial  )

◆ BENCHMARK() [4/5]

BENCHMARK ( BM_CalculatePi  ) -> Threads(8)

◆ BENCHMARK() [5/5]

BENCHMARK ( BM_LongTest  ) -> Range(1<< 4, 1<< 6)

◆ BENCHMARK_RANGE()

BENCHMARK_RANGE ( BM_CalculatePiRange  ,
,
256 *  256 
)

◆ BM_CalculatePi()

static void BM_CalculatePi ( benchmark::State &  state)
static

Definition at line 105 of file testBenchmark.cpp.

105  {
106  static const int depth = 256;
107  double pi = 0.0;
108  while (state.KeepRunning()) {
109  benchmark::DoNotOptimize( pi = CalculatePi(depth) );
110  }
111 }
double CalculatePi(int depth)

References CalculatePi().

◆ BM_CalculatePiRange()

static void BM_CalculatePiRange ( benchmark::State &  state)
static

Definition at line 95 of file testBenchmark.cpp.

95  {
96  double pi = 0.0;
97  while (state.KeepRunning())
98  pi = CalculatePi(state.range(0));
99  std::stringstream ss;
100  ss << pi;
101  state.SetLabel(ss.str());
102 }
double CalculatePi(int depth)

References CalculatePi().

◆ BM_Factorial()

static void BM_Factorial ( benchmark::State &  state)
static

Definition at line 74 of file testBenchmark.cpp.

74  {
75  int fac_42 = 0;
76  while (state.KeepRunning())
77  fac_42 = Factorial(8);
78  // Prevent compiler optimizations
79  std::stringstream ss;
80  ss << fac_42;
81  state.SetLabel(ss.str());
82 }
int BENCHMARK_NOINLINE Factorial(uint32_t n)

References Factorial().

◆ BM_LongTest()

static void BM_LongTest ( benchmark::State &  state)
static

Definition at line 117 of file testBenchmark.cpp.

117  {
118  double tracker = 0.0;
119  while (state.KeepRunning())
120  for (int i = 0; i < state.range(0); ++i)
121  benchmark::DoNotOptimize(tracker += i);
122 }

◆ BM_StringCopy()

static void BM_StringCopy ( benchmark::State &  state)
static

Definition at line 65 of file testBenchmark.cpp.

66 {
67  std::string x = "hello";
68  while (state.KeepRunning())
69  std::string copy(x);
70 }

◆ BM_StringCreation()

static void BM_StringCreation ( benchmark::State &  state)
static

Definition at line 55 of file testBenchmark.cpp.

56 {
57  while (state.KeepRunning())
58  std::string empty_string;
59 }

◆ CalculatePi()

double CalculatePi ( int  depth)

Definition at line 85 of file testBenchmark.cpp.

85  {
86  double pi = 0.0;
87  for (int i = 0; i < depth; ++i) {
88  double numerator = static_cast<double>(((i % 2) * 2) - 1);
89  double denominator = static_cast<double>((2 * i) - 1);
90  pi += numerator / denominator;
91  }
92  return (pi - 1.0) * 4;
93 }

Referenced by BM_CalculatePi(), and BM_CalculatePiRange().

◆ Factorial()

int BENCHMARK_NOINLINE Factorial ( uint32_t  n)

Definition at line 51 of file testBenchmark.cpp.

51  {
52  return (n == 1) ? 1 : n * Factorial(n - 1);
53 }
int BENCHMARK_NOINLINE Factorial(uint32_t n)

Referenced by BM_Factorial().

◆ main()

int main ( int  argc,
char *  argv[] 
)

Definition at line 133 of file testBenchmark.cpp.

134 {
135  benchmark::Initialize(&argc, argv);
136 
137  benchmark::RunSpecifiedBenchmarks();
138  return 0;
139 }// //