Bitcoin ABC  0.22.13
P2P Digital Currency
examples.cpp
Go to the documentation of this file.
1 // Copyright (c) 2015-2016 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  while (state.KeepRunning()) {
12  UninterruptibleSleep(std::chrono::milliseconds{100});
13  }
14 }
15 
17 
18 // Extremely fast-running benchmark:
19 #include <cmath>
20 
21 volatile double sum = 0.0; // volatile, global so not optimized away
22 
23 static void Trig(benchmark::State &state) {
24  double d = 0.01;
25  while (state.KeepRunning()) {
26  sum += sin(d);
27  d += 0.000001;
28  }
29 }
30 
31 BENCHMARK(Trig, 12 * 1000 * 1000);
static void Trig(benchmark::State &state)
Definition: examples.cpp:23
bool KeepRunning()
Definition: bench.h:71
volatile double sum
Definition: examples.cpp:21
static void Sleep100ms(benchmark::State &state)
Definition: examples.cpp:10
void UninterruptibleSleep(const std::chrono::microseconds &n)
Definition: time.cpp:20
BENCHMARK(Sleep100ms, 10)