Bitcoin Core  21.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 CODE_TO_TIME(benchmark::Bench& bench)
22 {
23  ... do any setup needed...
24  nanobench::Config().run([&] {
25  ... do stuff you want to time...
26  });
27  ... do any cleanup needed...
28 }
29 
30 BENCHMARK(CODE_TO_TIME);
31 
32  */
33 
34 namespace benchmark {
35 
37 
38 typedef std::function<void(Bench&)> BenchFunction;
39 
40 struct Args {
41  std::string regex_filter;
43  std::vector<double> asymptote;
44  std::string output_csv;
45  std::string output_json;
46 };
47 
49 {
50  typedef std::map<std::string, BenchFunction> BenchmarkMap;
51  static BenchmarkMap& benchmarks();
52 
53 public:
54  BenchRunner(std::string name, BenchFunction func);
55 
56  static void RunAll(const Args& args);
57 };
58 }
59 // BENCHMARK(foo) expands to: benchmark::BenchRunner bench_11foo("foo", foo);
60 #define BENCHMARK(n) \
61  benchmark::BenchRunner PASTE2(bench_, PASTE2(__LINE__, n))(STRINGIZE(n), n);
62 
63 #endif // BITCOIN_BENCH_BENCH_H
benchmark::Args::output_json
std::string output_json
Definition: bench.h:45
benchmark
Definition: bench.h:34
benchmark::BenchRunner
Definition: bench.h:48
benchmark::BenchRunner::RunAll
static void RunAll(const Args &args)
Definition: bench.cpp:46
ankerl::nanobench::Bench
Main entry point to nanobench's benchmarking facility.
Definition: nanobench.h:583
macros.h
benchmark::Args::regex_filter
std::string regex_filter
Definition: bench.h:41
benchmark::BenchFunction
std::function< void(Bench &)> BenchFunction
Definition: bench.h:38
nanobench.h
benchmark::Args
Definition: bench.h:40
benchmark::BenchRunner::benchmarks
static BenchmarkMap & benchmarks()
Definition: bench.cpp:35
name
const char * name
Definition: rest.cpp:43
benchmark::BenchRunner::BenchRunner
BenchRunner(std::string name, BenchFunction func)
Definition: bench.cpp:41
benchmark::Args::asymptote
std::vector< double > asymptote
Definition: bench.h:43
benchmark::BenchRunner::BenchmarkMap
std::map< std::string, BenchFunction > BenchmarkMap
Definition: bench.h:50
benchmark::Args::output_csv
std::string output_csv
Definition: bench.h:44
benchmark::Args::is_list_only
bool is_list_only
Definition: bench.h:42