Bitcoin ABC  0.24.11
P2P Digital Currency
bench_bitcoin.cpp
Go to the documentation of this file.
1 // Copyright (c) 2015-2019 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 #include <bench/bench.h>
6 
7 #include <crypto/sha256.h>
8 #include <util/strencodings.h>
9 #include <util/system.h>
10 
11 #include <memory>
12 
13 static const char *DEFAULT_BENCH_FILTER = ".*";
14 
15 static void SetupBenchArgs(ArgsManager &argsman) {
16  SetupHelpOptions(argsman);
17 
18  argsman.AddArg("-list", "List benchmarks without executing them",
20  argsman.AddArg("-filter=<regex>",
21  strprintf("Regular expression filter to select benchmark by "
22  "name (default: %s)",
25  argsman.AddArg("-asymptote=n1,n2,n3,...",
26  strprintf("Test asymptotic growth of the runtime of an "
27  "algorithm, if supported by the benchmark"),
29  argsman.AddArg(
30  "-output_csv=<output.csv>",
31  "Generate CSV file with the most important benchmark results.",
33  argsman.AddArg("-output_json=<output.json>",
34  "Generate JSON file with all benchmark results.",
36 }
37 
38 // parses a comma separated list like "10,20,30,50"
39 static std::vector<double> parseAsymptote(const std::string &str) {
40  std::stringstream ss(str);
41  std::vector<double> numbers;
42  double d;
43  char c;
44  while (ss >> d) {
45  numbers.push_back(d);
46  ss >> c;
47  }
48  return numbers;
49 }
50 
51 int main(int argc, char **argv) {
52  ArgsManager argsman;
53  SetupBenchArgs(argsman);
55  std::string error;
56  if (!argsman.ParseParameters(argc, argv, error)) {
57  tfm::format(std::cerr, "Error parsing command line arguments: %s\n",
58  error);
59  return EXIT_FAILURE;
60  }
61 
62  if (HelpRequested(argsman)) {
63  std::cout << argsman.GetHelpMessage();
64  return EXIT_SUCCESS;
65  }
66 
67  benchmark::Args args;
68  args.regex_filter = argsman.GetArg("-filter", DEFAULT_BENCH_FILTER);
69  args.is_list_only = argsman.GetBoolArg("-list", false);
70  args.asymptote = parseAsymptote(argsman.GetArg("-asymptote", ""));
71  args.output_csv = argsman.GetArg("-output_csv", "");
72  args.output_json = argsman.GetArg("-output_json", "");
73 
75 
76  return EXIT_SUCCESS;
77 }
benchmark::Args::output_json
std::string output_json
Definition: bench.h:46
ArgsManager::GetBoolArg
bool GetBoolArg(const std::string &strArg, bool fDefault) const
Return boolean argument or default value.
Definition: system.cpp:601
tinyformat::format
void format(std::ostream &out, const char *fmt, const Args &... args)
Format list of arguments to the stream according to given format string.
Definition: tinyformat.h:1111
SetupHelpOptions
void SetupHelpOptions(ArgsManager &args)
Add help options to the args manager.
Definition: system.cpp:760
ArgsManager::ALLOW_ANY
@ ALLOW_ANY
Definition: system.h:155
ArgsManager::GetHelpMessage
std::string GetHelpMessage() const
Get the help string.
Definition: system.cpp:682
parseAsymptote
static std::vector< double > parseAsymptote(const std::string &str)
Definition: bench_bitcoin.cpp:39
benchmark::BenchRunner::RunAll
static void RunAll(const Args &args)
Definition: bench.cpp:45
DEFAULT_BENCH_FILTER
static const char * DEFAULT_BENCH_FILTER
Definition: bench_bitcoin.cpp:13
benchmark::Args::regex_filter
std::string regex_filter
Definition: bench.h:42
SHA256AutoDetect
std::string SHA256AutoDetect()
Autodetect the best available SHA256 implementation.
Definition: sha256.cpp:746
HelpRequested
bool HelpRequested(const ArgsManager &args)
Definition: system.cpp:755
strencodings.h
SetupBenchArgs
static void SetupBenchArgs(ArgsManager &argsman)
Definition: bench_bitcoin.cpp:15
ArgsManager::AddArg
void AddArg(const std::string &name, const std::string &help, unsigned int flags, const OptionsCategory &cat)
Add argument.
Definition: system.cpp:649
ArgsManager::GetArg
std::string GetArg(const std::string &strArg, const std::string &strDefault) const
Return string argument or default value.
Definition: system.cpp:582
OptionsCategory::OPTIONS
@ OPTIONS
benchmark::Args
Definition: bench.h:41
ArgsManager::ParseParameters
bool ParseParameters(int argc, const char *const argv[], std::string &error)
Definition: system.cpp:330
bench.h
sha256.h
system.h
strprintf
#define strprintf
Format arguments and return the string or write to given std::ostream (see tinyformat::format doc for...
Definition: tinyformat.h:1201
benchmark::Args::asymptote
std::vector< double > asymptote
Definition: bench.h:44
ArgsManager
Definition: system.h:148
benchmark::Args::output_csv
std::string output_csv
Definition: bench.h:45
error
bool error(const char *fmt, const Args &... args)
Definition: system.h:48
benchmark::Args::is_list_only
bool is_list_only
Definition: bench.h:43
main
int main(int argc, char **argv)
Definition: bench_bitcoin.cpp:51