Changeset View
Changeset View
Standalone View
Standalone View
src/bench/util_time.cpp
// Copyright (c) 2019 The Bitcoin Core developers | // Copyright (c) 2019 The Bitcoin Core developers | ||||
// Distributed under the MIT software license, see the accompanying | // Distributed under the MIT software license, see the accompanying | ||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | // file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
#include <bench/bench.h> | #include <bench/bench.h> | ||||
#include <util/time.h> | #include <util/time.h> | ||||
static void BenchTimeDeprecated(benchmark::State &state) { | static void BenchTimeDeprecated(benchmark::Bench &bench) { | ||||
while (state.KeepRunning()) { | bench.run([&] { (void)GetTime(); }); | ||||
(void)GetTime(); | |||||
} | |||||
} | } | ||||
static void BenchTimeMock(benchmark::State &state) { | static void BenchTimeMock(benchmark::Bench &bench) { | ||||
SetMockTime(111); | SetMockTime(111); | ||||
while (state.KeepRunning()) { | bench.run([&] { (void)GetTime<std::chrono::seconds>(); }); | ||||
(void)GetTime<std::chrono::seconds>(); | |||||
} | |||||
SetMockTime(0); | SetMockTime(0); | ||||
} | } | ||||
static void BenchTimeMillis(benchmark::State &state) { | static void BenchTimeMillis(benchmark::Bench &bench) { | ||||
while (state.KeepRunning()) { | bench.run([&] { (void)GetTime<std::chrono::milliseconds>(); }); | ||||
(void)GetTime<std::chrono::milliseconds>(); | |||||
} | |||||
} | } | ||||
static void BenchTimeMillisSys(benchmark::State &state) { | static void BenchTimeMillisSys(benchmark::Bench &bench) { | ||||
while (state.KeepRunning()) { | bench.run([&] { (void)GetTimeMillis(); }); | ||||
(void)GetTimeMillis(); | |||||
} | |||||
} | } | ||||
BENCHMARK(BenchTimeDeprecated, 100000000); | BENCHMARK(BenchTimeDeprecated); | ||||
BENCHMARK(BenchTimeMillis, 6000000); | BENCHMARK(BenchTimeMillis); | ||||
BENCHMARK(BenchTimeMillisSys, 6000000); | BENCHMARK(BenchTimeMillisSys); | ||||
BENCHMARK(BenchTimeMock, 300000000); | BENCHMARK(BenchTimeMock); |