Bitcoin Core  0.19.99
P2P Digital Currency
examples.cpp
Go to the documentation of this file.
1 // Copyright (c) 2015-2019 The Bitcoin Core developers
2 // Distributed under the MIT software license, see the accompanying
3 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4 
5 #include <bench/bench.h>
6 #include <util/time.h>
7 
8 // Sanity test: this should loop ten times, and
9 // min/max/average should be close to 100ms.
10 static void Sleep100ms(benchmark::State& state)
11 {
12  while (state.KeepRunning()) {
13  UninterruptibleSleep(std::chrono::milliseconds{100});
14  }
15 }
16 
18 
19 // Extremely fast-running benchmark:
20 #include <math.h>
21 
22 volatile double sum = 0.0; // volatile, global so not optimized away
23 
24 static void Trig(benchmark::State& state)
25 {
26  double d = 0.01;
27  while (state.KeepRunning()) {
28  sum += sin(d);
29  d += 0.000001;
30  }
31 }
32 
33 BENCHMARK(Trig, 12 * 1000 * 1000);
static void Trig(benchmark::State &state)
Definition: examples.cpp:24
bool KeepRunning()
Definition: bench.h:72
volatile double sum
Definition: examples.cpp:22
static void Sleep100ms(benchmark::State &state)
Definition: examples.cpp:10
void UninterruptibleSleep(const std::chrono::microseconds &n)
Definition: time.cpp:19
BENCHMARK(Sleep100ms, 10)