Bitcoin Core  24.1.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 {
47  std::chrono::milliseconds min_time;
48  std::vector<double> asymptote;
51  std::string regex_filter;
52 };
53 
55 {
56  typedef std::map<std::string, BenchFunction> BenchmarkMap;
57  static BenchmarkMap& benchmarks();
58 
59 public:
60  BenchRunner(std::string name, BenchFunction func);
61 
62  static void RunAll(const Args& args);
63 };
64 } // namespace benchmark
65 
66 // BENCHMARK(foo) expands to: benchmark::BenchRunner bench_11foo("foo", foo);
67 #define BENCHMARK(n) \
68  benchmark::BenchRunner PASTE2(bench_, PASTE2(__LINE__, n))(STRINGIZE(n), n);
69 
70 #endif // BITCOIN_BENCH_BENCH_H
BenchRunner(std::string name, BenchFunction func)
Definition: bench.cpp:50
std::chrono::milliseconds min_time
Definition: bench.h:47
std::vector< double > asymptote
Definition: bench.h:48
ArgsManager args
const char * name
Definition: rest.cpp:46
fs::path output_json
Definition: bench.h:50
std::function< void(Bench &)> BenchFunction
Definition: bench.h:42
std::map< std::string, BenchFunction > BenchmarkMap
Definition: bench.h:56
static void RunAll(const Args &args)
Definition: bench.cpp:55
bool sanity_check
Definition: bench.h:46
bool is_list_only
Definition: bench.h:45
fs::path output_csv
Definition: bench.h:49
static BenchmarkMap & benchmarks()
Definition: bench.cpp:44
Main entry point to nanobench&#39;s benchmarking facility.
Definition: nanobench.h:616
std::string regex_filter
Definition: bench.h:51
Path class wrapper to block calls to the fs::path(std::string) implicit constructor and the fs::path:...
Definition: fs.h:30