Bitcoin ABC  0.24.7
P2P Digital Currency
bench.h
Go to the documentation of this file.
1 // Copyright (c) 2015-2016 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 
16 #include <boost/preprocessor/cat.hpp>
17 #include <boost/preprocessor/stringize.hpp>
18 
19 /*
20  * Usage:
21 
22 static void CODE_TO_TIME(benchmark::Bench& bench)
23 {
24  ... do any setup needed...
25  nanobench::Config().run([&] {
26  ... do stuff you want to time...
27  });
28  ... do any cleanup needed...
29 }
30 
31 BENCHMARK(CODE_TO_TIME);
32 
33  */
34 
35 namespace benchmark {
36 
38 
39 typedef std::function<void(Bench &)> BenchFunction;
40 
41 struct Args {
42  std::string regex_filter;
44  std::vector<double> asymptote;
45  std::string output_csv;
46  std::string output_json;
47 };
48 
49 class BenchRunner {
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 } // namespace benchmark
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))( \
62  BOOST_PP_STRINGIZE(n), n);
63 
64 #endif // BITCOIN_BENCH_BENCH_H
benchmark::Args::output_json
std::string output_json
Definition: bench.h:46
benchmark
Definition: bench.h:35
benchmark::BenchRunner
Definition: bench.h:49
benchmark::BenchRunner::RunAll
static void RunAll(const Args &args)
Definition: bench.cpp:45
ankerl::nanobench::Bench
Main entry point to nanobench's benchmarking facility.
Definition: nanobench.h:583
benchmark::Args::regex_filter
std::string regex_filter
Definition: bench.h:42
nanobench.h
benchmark::Args
Definition: bench.h:41
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:40
benchmark::Args::asymptote
std::vector< double > asymptote
Definition: bench.h:44
benchmark::BenchFunction
std::function< void(Bench &)> BenchFunction
Definition: bench.h:39
benchmark::BenchRunner::BenchmarkMap
std::map< std::string, BenchFunction > BenchmarkMap
Definition: bench.h:50
benchmark::Args::output_csv
std::string output_csv
Definition: bench.h:45
benchmark::Args::is_list_only
bool is_list_only
Definition: bench.h:43