Bitcoin Core
31.1.0
P2P Digital Currency
Toggle main menu visibility
Loading...
Searching...
No Matches
src
bench
bench.h
Go to the documentation of this file.
1
// Copyright (c) 2015-present 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 <
bench/nanobench.h
>
// IWYU pragma: export
9
#include <
util/fs.h
>
10
#include <
util/macros.h
>
11
12
#include <chrono>
13
#include <functional>
14
#include <map>
15
#include <string>
16
#include <vector>
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
39
using
ankerl::nanobench::Bench;
40
41
using
BenchFunction
= std::function<void(
Bench
&)>;
42
43
struct
Args
{
44
bool
is_list_only
;
45
bool
sanity_check
;
46
std::chrono::milliseconds
min_time
;
47
std::vector<double>
asymptote
;
48
fs::path
output_csv
;
49
fs::path
output_json
;
50
std::string
regex_filter
;
51
std::vector<std::string>
setup_args
;
52
};
53
54
class
BenchRunner
55
{
56
// maps from "name" -> function
57
using
BenchmarkMap
= std::map<std::string, BenchFunction>;
58
static
BenchmarkMap
&
benchmarks
();
59
60
public
:
61
BenchRunner
(std::string
name
,
BenchFunction
func);
62
63
static
void
RunAll
(
const
Args
&
args
);
64
};
65
}
// namespace benchmark
66
67
// BENCHMARK(foo); expands to: benchmark::BenchRunner bench_runner_foo{"foo", foo};
68
#define BENCHMARK(n) \
69
benchmark::BenchRunner PASTE2(bench_runner_, n) { STRINGIZE(n), n }
70
71
#endif
// BITCOIN_BENCH_BENCH_H
args
ArgsManager & args
Definition
bitcoind.cpp:277
ankerl::nanobench::Bench
Main entry point to nanobench's benchmarking facility.
Definition
nanobench.h:627
benchmark::BenchRunner::RunAll
static void RunAll(const Args &args)
Definition
bench.cpp:78
benchmark::BenchRunner::BenchRunner
BenchRunner(std::string name, BenchFunction func)
Definition
bench.cpp:73
benchmark::BenchRunner::BenchmarkMap
std::map< std::string, BenchFunction > BenchmarkMap
Definition
bench.h:57
benchmark::BenchRunner::benchmarks
static BenchmarkMap & benchmarks()
Definition
bench.cpp:67
fs.h
macros.h
benchmark
Definition
bench.cpp:65
benchmark::BenchFunction
std::function< void(Bench &)> BenchFunction
Definition
bench.h:41
nanobench.h
name
const char * name
Definition
rest.cpp:48
benchmark::Args
Definition
bench.h:43
benchmark::Args::setup_args
std::vector< std::string > setup_args
Definition
bench.h:51
benchmark::Args::regex_filter
std::string regex_filter
Definition
bench.h:50
benchmark::Args::output_json
fs::path output_json
Definition
bench.h:49
benchmark::Args::output_csv
fs::path output_csv
Definition
bench.h:48
benchmark::Args::asymptote
std::vector< double > asymptote
Definition
bench.h:47
benchmark::Args::sanity_check
bool sanity_check
Definition
bench.h:45
benchmark::Args::min_time
std::chrono::milliseconds min_time
Definition
bench.h:46
benchmark::Args::is_list_only
bool is_list_only
Definition
bench.h:44
Generated on
for Bitcoin Core by
1.17.0