Bitcoin Core  22.99.0
P2P Digital Currency
bench.h
Go to the documentation of this file.
1 // Copyright (c) 2015-2021 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 <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 
22 static 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 
34 BENCHMARK(NameOfYourBenchmarkFunction);
35 
36  */
37 
38 namespace benchmark {
39 
41 
42 typedef std::function<void(Bench&)> BenchFunction;
43 
44 struct Args {
46  std::chrono::milliseconds min_time;
47  std::vector<double> asymptote;
50  std::string regex_filter;
51 };
52 
54 {
55  typedef std::map<std::string, BenchFunction> BenchmarkMap;
56  static BenchmarkMap& benchmarks();
57 
58 public:
59  BenchRunner(std::string name, BenchFunction func);
60 
61  static void RunAll(const Args& args);
62 };
63 } // namespace benchmark
64 
65 // BENCHMARK(foo) expands to: benchmark::BenchRunner bench_11foo("foo", foo);
66 #define BENCHMARK(n) \
67  benchmark::BenchRunner PASTE2(bench_, PASTE2(__LINE__, n))(STRINGIZE(n), n);
68 
69 #endif // BITCOIN_BENCH_BENCH_H
benchmark
Definition: bench.h:38
fs.h
benchmark::BenchRunner
Definition: bench.h:53
benchmark::BenchRunner::RunAll
static void RunAll(const Args &args)
Definition: bench.cpp:55
benchmark::Args::min_time
std::chrono::milliseconds min_time
Definition: bench.h:46
ankerl::nanobench::Bench
Main entry point to nanobench's benchmarking facility.
Definition: nanobench.h:616
macros.h
benchmark::Args::regex_filter
std::string regex_filter
Definition: bench.h:50
benchmark::BenchFunction
std::function< void(Bench &)> BenchFunction
Definition: bench.h:42
nanobench.h
fs::path
Path class wrapper to block calls to the fs::path(std::string) implicit constructor and the fs::path:...
Definition: fs.h:29
benchmark::Args::output_json
fs::path output_json
Definition: bench.h:49
benchmark::Args::output_csv
fs::path output_csv
Definition: bench.h:48
benchmark::Args
Definition: bench.h:44
benchmark::BenchRunner::benchmarks
static BenchmarkMap & benchmarks()
Definition: bench.cpp:44
name
const char * name
Definition: rest.cpp:52
benchmark::BenchRunner::BenchRunner
BenchRunner(std::string name, BenchFunction func)
Definition: bench.cpp:50
benchmark::Args::asymptote
std::vector< double > asymptote
Definition: bench.h:47
benchmark::BenchRunner::BenchmarkMap
std::map< std::string, BenchFunction > BenchmarkMap
Definition: bench.h:55
benchmark::Args::is_list_only
bool is_list_only
Definition: bench.h:45
args
ArgsManager args
Definition: notifications.cpp:36