Bitcoin ABC
0.22.13
P2P Digital Currency
src
bench
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
16
BENCHMARK
(
Sleep100ms
, 10);
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);
time.h
Trig
static void Trig(benchmark::State &state)
Definition:
examples.cpp:23
benchmark::State::KeepRunning
bool KeepRunning()
Definition:
bench.h:71
sum
volatile double sum
Definition:
examples.cpp:21
Sleep100ms
static void Sleep100ms(benchmark::State &state)
Definition:
examples.cpp:10
bench.h
UninterruptibleSleep
void UninterruptibleSleep(const std::chrono::microseconds &n)
Definition:
time.cpp:20
benchmark::State
Definition:
bench.h:55
BENCHMARK
BENCHMARK(Sleep100ms, 10)
Generated on Tue Jan 26 2021 19:53:12 for Bitcoin ABC by
1.8.13