Bitcoin ABC 0.26.3
P2P Digital Currency
Loading...
Searching...
No Matches
bench.h
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#ifndef BITCOIN_BENCH_BENCH_H
6#define BITCOIN_BENCH_BENCH_H
7
8#include <util/fs.h>
9#include <util/macros.h>
10
11#include <chrono>
12#include <functional>
13#include <map>
14#include <string>
15#include <vector>
16
17#include <bench/nanobench.h>
18
19/*
20 * Usage:
21
22static void NameOfYourBenchmarkFunction(benchmark::Bench& bench)
23{
24 ...do any setup needed...
25
26 bench.run([&] {
27 ...do stuff you want to time; refer to src/bench/nanobench.h
28 for more information and the options that can be passed here...
29 });
30
31 ...do any cleanup needed...
32}
33
34BENCHMARK(NameOfYourBenchmarkFunction);
35
36 */
37
38namespace benchmark {
39
41
42typedef std::function<void(Bench &)> BenchFunction;
43
44struct Args {
46 std::chrono::milliseconds min_time;
47 std::vector<double> asymptote;
50 std::string regex_filter;
51};
52
54 typedef std::map<std::string, BenchFunction> BenchmarkMap;
55 static BenchmarkMap &benchmarks();
56
57public:
58 BenchRunner(std::string name, BenchFunction func);
59
60 static void RunAll(const Args &args);
61};
62} // namespace benchmark
63
64// BENCHMARK(foo) expands to: benchmark::BenchRunner bench_11foo("foo", foo);
65#define BENCHMARK(n) \
66 benchmark::BenchRunner PASTE2(bench_, PASTE2(__LINE__, n))(STRINGIZE(n), n);
67
68#endif // BITCOIN_BENCH_BENCH_H
Main entry point to nanobench's benchmarking facility.
Definition nanobench.h:616
static BenchmarkMap & benchmarks()
Definition bench.cpp:41
static void RunAll(const Args &args)
Definition bench.cpp:51
std::map< std::string, BenchFunction > BenchmarkMap
Definition bench.h:54
Path class wrapper to block calls to the fs::path(std::string) implicit constructor and the fs::path:...
Definition fs.h:30
std::function< void(Bench &)> BenchFunction
Definition bench.h:42
T GetRand(T nMax=std::numeric_limits< T >::max()) noexcept
Generate a uniform random integer of type T in the range [0..nMax) nMax defaults to std::numeric_limi...
Definition random.h:85
const char * name
Definition rest.cpp:47
std::string regex_filter
Definition bench.h:50
fs::path output_json
Definition bench.h:49
fs::path output_csv
Definition bench.h:48
std::vector< double > asymptote
Definition bench.h:47
std::chrono::milliseconds min_time
Definition bench.h:46
bool is_list_only
Definition bench.h:45