mirror of
https://github.com/Retropex/bitcoin.git
synced 2025-06-04 00:12:33 +02:00

When it is not easily possible to stabilize benchmark machine and code the argument -min_time can be used to specify a minimum duration that a benchmark should take. E.g. choose -min_time=1000 if you are willing to wait about 1 second for each benchmark result. The default is now set to 10ms instead of 0, which should make runs on fast machines more stable with negligible slowdown.
69 lines
1.5 KiB
C++
69 lines
1.5 KiB
C++
// Copyright (c) 2015-2020 The Bitcoin Core developers
|
|
// Distributed under the MIT software license, see the accompanying
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
#ifndef BITCOIN_BENCH_BENCH_H
|
|
#define BITCOIN_BENCH_BENCH_H
|
|
|
|
#include <util/macros.h>
|
|
|
|
#include <chrono>
|
|
#include <functional>
|
|
#include <map>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
#include <bench/nanobench.h>
|
|
|
|
/*
|
|
* Usage:
|
|
|
|
static void NameOfYourBenchmarkFunction(benchmark::Bench& bench)
|
|
{
|
|
...do any setup needed...
|
|
|
|
bench.run([&] {
|
|
...do stuff you want to time; refer to src/bench/nanobench.h
|
|
for more information and the options that can be passed here...
|
|
});
|
|
|
|
...do any cleanup needed...
|
|
}
|
|
|
|
BENCHMARK(NameOfYourBenchmarkFunction);
|
|
|
|
*/
|
|
|
|
namespace benchmark {
|
|
|
|
using ankerl::nanobench::Bench;
|
|
|
|
typedef std::function<void(Bench&)> BenchFunction;
|
|
|
|
struct Args {
|
|
std::string regex_filter;
|
|
bool is_list_only;
|
|
std::chrono::milliseconds min_time;
|
|
std::vector<double> asymptote;
|
|
std::string output_csv;
|
|
std::string output_json;
|
|
};
|
|
|
|
class BenchRunner
|
|
{
|
|
typedef std::map<std::string, BenchFunction> BenchmarkMap;
|
|
static BenchmarkMap& benchmarks();
|
|
|
|
public:
|
|
BenchRunner(std::string name, BenchFunction func);
|
|
|
|
static void RunAll(const Args& args);
|
|
};
|
|
} // namespace benchmark
|
|
|
|
// BENCHMARK(foo) expands to: benchmark::BenchRunner bench_11foo("foo", foo);
|
|
#define BENCHMARK(n) \
|
|
benchmark::BenchRunner PASTE2(bench_, PASTE2(__LINE__, n))(STRINGIZE(n), n);
|
|
|
|
#endif // BITCOIN_BENCH_BENCH_H
|