Bitcoin ABC  0.22.12
P2P Digital Currency
util_time.cpp
Go to the documentation of this file.
1 // Copyright (c) 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 
7 #include <util/time.h>
8 
9 static void BenchTimeDeprecated(benchmark::State &state) {
10  while (state.KeepRunning()) {
11  (void)GetTime();
12  }
13 }
14 
15 static void BenchTimeMock(benchmark::State &state) {
16  SetMockTime(111);
17  while (state.KeepRunning()) {
18  (void)GetTime<std::chrono::seconds>();
19  }
20  SetMockTime(0);
21 }
22 
23 static void BenchTimeMillis(benchmark::State &state) {
24  while (state.KeepRunning()) {
25  (void)GetTime<std::chrono::milliseconds>();
26  }
27 }
28 
29 static void BenchTimeMillisSys(benchmark::State &state) {
30  while (state.KeepRunning()) {
31  (void)GetTimeMillis();
32  }
33 }
34 
35 BENCHMARK(BenchTimeDeprecated, 100000000);
36 BENCHMARK(BenchTimeMillis, 6000000);
38 BENCHMARK(BenchTimeMock, 300000000);
int64_t GetTimeMillis()
Returns the system time (not mockable)
Definition: time.cpp:59
static void BenchTimeDeprecated(benchmark::State &state)
Definition: util_time.cpp:9
bool KeepRunning()
Definition: bench.h:75
void SetMockTime(int64_t nMockTimeIn)
For testing.
Definition: time.cpp:50
BENCHMARK(BenchTimeDeprecated, 100000000)
static void BenchTimeMillis(benchmark::State &state)
Definition: util_time.cpp:23
static void BenchTimeMock(benchmark::State &state)
Definition: util_time.cpp:15
static void BenchTimeMillisSys(benchmark::State &state)
Definition: util_time.cpp:29
int64_t GetTime()
Return system time (or mocked time, if set)
Definition: time.cpp:27