PIVX Core  5.6.99
P2P Digital Currency
bench_pivx.cpp
Go to the documentation of this file.
1 // Copyright (c) 2015-2016 The Bitcoin Core developers
2 // Copyright (c) 2021-2022 The PIVX Core developers
3 // Distributed under the MIT software license, see the accompanying
4 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
5 
6 #include <bench/bench.h>
7 
8 #include <bls/bls_wrapper.h>
9 #include <crypto/sha256.h>
10 #include <key.h>
11 #include <random.h>
12 #include <utilstrencodings.h>
13 #include <validation.h>
14 
15 #include <memory>
16 
17 static const int64_t DEFAULT_BENCH_EVALUATIONS = 5;
18 static const char* DEFAULT_BENCH_FILTER = ".*";
19 static const char* DEFAULT_BENCH_SCALING = "1.0";
20 static const char* DEFAULT_BENCH_PRINTER = "console";
21 static const char* DEFAULT_PLOT_PLOTLYURL = "https://cdn.plot.ly/plotly-latest.min.js";
22 static const int64_t DEFAULT_PLOT_WIDTH = 1024;
23 static const int64_t DEFAULT_PLOT_HEIGHT = 768;
24 
25 void InitBLSTests();
26 void CleanupBLSTests();
27 void CleanupBLSDkgTests();
28 
29 int main(int argc, char** argv)
30 {
31  gArgs.ParseParameters(argc, argv);
32 
33  if (gArgs.IsArgSet("-?") || gArgs.IsArgSet("-h") || gArgs.IsArgSet("-help")) {
34  std::cout << HelpMessageGroup(_("Options:"))
35  << HelpMessageOpt("-?", _("Print this help message and exit"))
36  << HelpMessageOpt("-list", _("List benchmarks without executing them. Can be combined with -scaling and -filter"))
37  << HelpMessageOpt("-evals=<n>", strprintf(_("Number of measurement evaluations to perform. (default: %u)"), DEFAULT_BENCH_EVALUATIONS))
38  << HelpMessageOpt("-filter=<regex>", strprintf(_("Regular expression filter to select benchmark by name (default: %s)"), DEFAULT_BENCH_FILTER))
39  << HelpMessageOpt("-scaling=<n>", strprintf(_("Scaling factor for benchmark's runtime (default: %u)"), DEFAULT_BENCH_SCALING))
40  << HelpMessageOpt("-printer=(console|plot)", strprintf(_("Choose printer format. console: print data to console. plot: Print results as HTML graph (default: %s)"), DEFAULT_BENCH_PRINTER))
41  << HelpMessageOpt("-plot-plotlyurl=<uri>", strprintf(_("URL to use for plotly.js (default: %s)"), DEFAULT_PLOT_PLOTLYURL))
42  << HelpMessageOpt("-plot-width=<x>", strprintf(_("Plot width in pixel (default: %u)"), DEFAULT_PLOT_WIDTH))
43  << HelpMessageOpt("-plot-height=<x>", strprintf(_("Plot height in pixel (default: %u)"), DEFAULT_PLOT_HEIGHT));
44 
45  return EXIT_SUCCESS;
46  }
47 
48  RandomInit();
49  ECC_Start();
50  ECCVerifyHandle globalVerifyHandle;
51  RandomInit();
52  BLSInit();
53  InitBLSTests();
55  g_logger->m_print_to_file = false; // don't want to write to debug.log file
56 
57  int64_t evaluations = gArgs.GetArg("-evals", DEFAULT_BENCH_EVALUATIONS);
58  std::string regex_filter = gArgs.GetArg("-filter", DEFAULT_BENCH_FILTER);
59  std::string scaling_str = gArgs.GetArg("-scaling", DEFAULT_BENCH_SCALING);
60  bool is_list_only = gArgs.GetBoolArg("-list", false);
61 
62  double scaling_factor;
63  if (!ParseDouble(scaling_str, &scaling_factor)) {
64  fprintf(stderr, "Error parsing scaling factor as double: %s\n", scaling_str.c_str());
65  return EXIT_FAILURE;
66  }
67 
68  std::unique_ptr<benchmark::Printer> printer(new benchmark::ConsolePrinter());
69  std::string printer_arg = gArgs.GetArg("-printer", DEFAULT_BENCH_PRINTER);
70  if ("plot" == printer_arg) {
71  printer.reset(new benchmark::PlotlyPrinter(
72  gArgs.GetArg("-plot-plotlyurl", DEFAULT_PLOT_PLOTLYURL),
73  gArgs.GetArg("-plot-width", DEFAULT_PLOT_WIDTH),
74  gArgs.GetArg("-plot-height", DEFAULT_PLOT_HEIGHT)));
75  }
76 
77  benchmark::BenchRunner::RunAll(*printer, evaluations, scaling_factor, regex_filter, is_list_only);
78 
79  // need to be called before global destructors kick in (PoolAllocator is needed due to many BLSSecretKeys)
82 
83  ECC_Stop();
84 
85  return EXIT_SUCCESS;
86 }
void InitBLSTests()
Definition: bls.cpp:15
int main(int argc, char **argv)
Definition: bench_pivx.cpp:29
void CleanupBLSDkgTests()
Definition: bls_dkg.cpp:133
void CleanupBLSTests()
Definition: bls.cpp:20
bool BLSInit()
void ParseParameters(int argc, const char *const argv[])
Definition: system.cpp:371
bool IsArgSet(const std::string &strArg) const
Return true if the given argument has been manually set.
Definition: system.cpp:425
std::string GetArg(const std::string &strArg, const std::string &strDefault) const
Return string argument or default value.
Definition: system.cpp:449
bool GetBoolArg(const std::string &strArg, bool fDefault) const
Return boolean argument or default value.
Definition: system.cpp:465
bool m_print_to_file
Definition: logging.h:94
Users of this module must hold an ECCVerifyHandle.
Definition: pubkey.h:273
static void RunAll(Printer &printer, uint64_t num_evals, double scaling, const std::string &filter, bool is_list_only)
Definition: bench.cpp:99
char ** argv
Definition: fuzz.cpp:52
void ECC_Start()
Initialize the elliptic curve support.
Definition: key.cpp:344
void ECC_Stop()
Deinitialize the elliptic curve support.
Definition: key.cpp:361
BCLog::Logger *const g_logger
NOTE: the logger instances is leaked on exit.
Definition: logging.cpp:26
void RandomInit()
Initialize global RNG state and log any CPU features that are used.
Definition: random.cpp:716
ArgsManager gArgs
Definition: system.cpp:89
void SetupEnvironment()
Definition: system.cpp:1043
std::string HelpMessageGroup(const std::string &message)
Format a string to be used as group of options in help messages.
Definition: system.cpp:499
std::string HelpMessageOpt(const std::string &option, const std::string &message)
Format a string to be used as option description in help messages.
Definition: system.cpp:503
std::string _(const char *psz)
Translation function: Call Translate signal on UI interface, which returns a Optional result.
Definition: system.h:65
#define strprintf
Definition: tinyformat.h:1056
bool ParseDouble(const std::string &str, double *out)
Convert string to double with strict parse error feedback.