Bitcoin Core  22.99.0
P2P Digital Currency
bench.h
Go to the documentation of this file.
1 // Copyright (c) 2015-2020 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/macros.h>
9 
10 #include <chrono>
11 #include <functional>
12 #include <map>
13 #include <string>
14 #include <vector>
15 
16 #include <bench/nanobench.h>
17 
18 /*
19  * Usage:
20 
21 static void NameOfYourBenchmarkFunction(benchmark::Bench& bench)
22 {
23  ...do any setup needed...
24 
25  bench.run([&] {
26  ...do stuff you want to time; refer to src/bench/nanobench.h
27  for more information and the options that can be passed here...
28  });
29 
30  ...do any cleanup needed...
31 }
32 
33 BENCHMARK(NameOfYourBenchmarkFunction);
34 
35  */
36 
37 namespace benchmark {
38 
40 
41 typedef std::function<void(Bench&)> BenchFunction;
42 
43 struct Args {
45  std::chrono::milliseconds min_time;
46  std::vector<double> asymptote;
47  std::string output_csv;
48  std::string output_json;
49  std::string regex_filter;
50 };
51 
53 {
54  typedef std::map<std::string, BenchFunction> BenchmarkMap;
55  static BenchmarkMap& benchmarks();
56 
57 public:
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
benchmark::Args::output_json
std::string output_json
Definition: bench.h:48
benchmark
Definition: bench.h:37
benchmark::BenchRunner
Definition: bench.h:52
benchmark::BenchRunner::RunAll
static void RunAll(const Args &args)
Definition: bench.cpp:53
benchmark::Args::min_time
std::chrono::milliseconds min_time
Definition: bench.h:45
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:49
benchmark::BenchFunction
std::function< void(Bench &)> BenchFunction
Definition: bench.h:41
nanobench.h
benchmark::Args
Definition: bench.h:43
benchmark::BenchRunner::benchmarks
static BenchmarkMap & benchmarks()
Definition: bench.cpp:42
name
const char * name
Definition: rest.cpp:43
benchmark::BenchRunner::BenchRunner
BenchRunner(std::string name, BenchFunction func)
Definition: bench.cpp:48
benchmark::Args::asymptote
std::vector< double > asymptote
Definition: bench.h:46
benchmark::BenchRunner::BenchmarkMap
std::map< std::string, BenchFunction > BenchmarkMap
Definition: bench.h:54
benchmark::Args::output_csv
std::string output_csv
Definition: bench.h:47
benchmark::Args::is_list_only
bool is_list_only
Definition: bench.h:44