34#include <benchmark/benchmark.h>
45# define BENCHMARK_NOINLINE __attribute__((noinline))
47# define BENCHMARK_NOINLINE
52 return (n == 1) ? 1 : n *
Factorial(n - 1);
57 while (state.KeepRunning())
58 std::string empty_string;
67 std::string x =
"hello";
68 while (state.KeepRunning())
76 while (state.KeepRunning())
81 state.SetLabel(ss.str());
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;
92 return (pi - 1.0) * 4;
97 while (state.KeepRunning())
101 state.SetLabel(ss.str());
106 static const int depth = 256;
108 while (state.KeepRunning()) {
109 benchmark::DoNotOptimize( pi =
CalculatePi(depth) );
118 double tracker = 0.0;
119 while (state.KeepRunning())
120 for (
int i = 0; i < state.range(0); ++i)
121 benchmark::DoNotOptimize(tracker += i);
133int main(
int argc,
char* argv[])
135 benchmark::Initialize(&argc, argv);
137 benchmark::RunSpecifiedBenchmarks();
static void BM_StringCreation(benchmark::State &state)
#define BENCHMARK_NOINLINE
BENCHMARK(BM_StringCreation)
static void BM_CalculatePiRange(benchmark::State &state)
static void BM_CalculatePi(benchmark::State &state)
static void BM_StringCopy(benchmark::State &state)
double CalculatePi(int depth)
static void BM_Factorial(benchmark::State &state)
int BENCHMARK_NOINLINE Factorial(uint32_t n)
static void BM_LongTest(benchmark::State &state)
BENCHMARK_RANGE(BM_CalculatePiRange, 1, 256 *256)