DGtal  0.9.3
Macros | Functions
testBenchmark.cpp File Reference
#include <iostream>
#include "DGtal/base/Common.h"
#include "ConfigTest.h"
#include "DGtal/helpers/StdDefs.h"
#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, 1024 *1024)
 
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<< 8)
 
int main (int argc, const 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 49 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<< 8)

◆ BENCHMARK_RANGE()

BENCHMARK_RANGE ( BM_CalculatePiRange  ,
,
1024 *  1024 
)

Referenced by BM_CalculatePiRange().

◆ BM_CalculatePi()

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

Definition at line 107 of file testBenchmark.cpp.

References BENCHMARK(), and CalculatePi().

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

◆ BM_CalculatePiRange()

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

Definition at line 97 of file testBenchmark.cpp.

References BENCHMARK_RANGE(), and CalculatePi().

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

◆ BM_Factorial()

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

Definition at line 76 of file testBenchmark.cpp.

References BENCHMARK(), and Factorial().

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

◆ BM_LongTest()

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

Definition at line 119 of file testBenchmark.cpp.

References BENCHMARK().

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

◆ BM_StringCopy()

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

Definition at line 67 of file testBenchmark.cpp.

References BENCHMARK().

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

◆ BM_StringCreation()

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

Definition at line 57 of file testBenchmark.cpp.

References BENCHMARK().

58 {
59  while (state.KeepRunning())
60  std::string empty_string;
61 }

◆ CalculatePi()

double CalculatePi ( int  depth)

Definition at line 87 of file testBenchmark.cpp.

Referenced by BM_CalculatePi(), and BM_CalculatePiRange().

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

◆ Factorial()

int BENCHMARK_NOINLINE Factorial ( uint32_t  n)

Definition at line 53 of file testBenchmark.cpp.

Referenced by BM_Factorial().

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

◆ main()

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

Definition at line 135 of file testBenchmark.cpp.

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