Bitcoin Core  0.20.99
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 <chrono>
9 #include <functional>
10 #include <map>
11 #include <string>
12 #include <vector>
13 
14 #include <bench/nanobench.h>
15 #include <boost/preprocessor/cat.hpp>
16 #include <boost/preprocessor/stringize.hpp>
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");
60 #define BENCHMARK(n) \
61  benchmark::BenchRunner BOOST_PP_CAT(bench_, BOOST_PP_CAT(__LINE__, n))(BOOST_PP_STRINGIZE(n), n);
62 
63 #endif // BITCOIN_BENCH_BENCH_H
std::string output_json
Definition: bench.h:45
std::vector< double > asymptote
Definition: bench.h:43
std::string output_csv
Definition: bench.h:44
const char * name
Definition: rest.cpp:41
std::function< void(Bench &)> BenchFunction
Definition: bench.h:38
std::map< std::string, BenchFunction > BenchmarkMap
Definition: bench.h:50
bool is_list_only
Definition: bench.h:42
Main entry point to nanobench&#39;s benchmarking facility.
Definition: nanobench.h:583
std::string regex_filter
Definition: bench.h:41