Fabcoin Core  0.16.2
P2P Digital Currency
bench_fabcoin.cpp
Go to the documentation of this file.
1 // Copyright (c) 2015-2017 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 <key.h>
9 #include <validation.h>
10 #include <util.h>
11 #include <random.h>
12 
13 #include <boost/lexical_cast.hpp>
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 int
26 main(int argc, char** argv)
27 {
28  gArgs.ParseParameters(argc, argv);
29 
30  if (gArgs.IsArgSet("-?") || gArgs.IsArgSet("-h") || gArgs.IsArgSet("-help")) {
31  std::cout << HelpMessageGroup(_("Options:"))
32  << HelpMessageOpt("-?", _("Print this help message and exit"))
33  << HelpMessageOpt("-list", _("List benchmarks without executing them. Can be combined with -scaling and -filter"))
34  << HelpMessageOpt("-evals=<n>", strprintf(_("Number of measurement evaluations to perform. (default: %u)"), DEFAULT_BENCH_EVALUATIONS))
35  << HelpMessageOpt("-filter=<regex>", strprintf(_("Regular expression filter to select benchmark by name (default: %s)"), DEFAULT_BENCH_FILTER))
36  << HelpMessageOpt("-scaling=<n>", strprintf(_("Scaling factor for benchmark's runtime (default: %u)"), DEFAULT_BENCH_SCALING))
37  << HelpMessageOpt("-printer=(console|plot)", strprintf(_("Choose printer format. console: print data to console. plot: Print results as HTML graph (default: %s)"), DEFAULT_BENCH_PRINTER))
38  << HelpMessageOpt("-plot-plotlyurl=<uri>", strprintf(_("URL to use for plotly.js (default: %s)"), DEFAULT_PLOT_PLOTLYURL))
39  << HelpMessageOpt("-plot-width=<x>", strprintf(_("Plot width in pixel (default: %u)"), DEFAULT_PLOT_WIDTH))
40  << HelpMessageOpt("-plot-height=<x>", strprintf(_("Plot height in pixel (default: %u)"), DEFAULT_PLOT_HEIGHT));
41 
42  return 0;
43  }
44 
46  RandomInit();
47  ECC_Start();
49  fPrintToDebugLog = false; // don't want to write to debug.log file
50 
51  int64_t evaluations = gArgs.GetArg("-evals", DEFAULT_BENCH_EVALUATIONS);
52  std::string regex_filter = gArgs.GetArg("-filter", DEFAULT_BENCH_FILTER);
53  std::string scaling_str = gArgs.GetArg("-scaling", DEFAULT_BENCH_SCALING);
54  bool is_list_only = gArgs.GetBoolArg("-list", false);
55 
56  double scaling_factor = boost::lexical_cast<double>(scaling_str);
57 
58 
59  std::unique_ptr<benchmark::Printer> printer(new benchmark::ConsolePrinter());
60  std::string printer_arg = gArgs.GetArg("-printer", DEFAULT_BENCH_PRINTER);
61  if ("plot" == printer_arg) {
62  printer.reset(new benchmark::PlotlyPrinter(
63  gArgs.GetArg("-plot-plotlyurl", DEFAULT_PLOT_PLOTLYURL),
64  gArgs.GetArg("-plot-width", DEFAULT_PLOT_WIDTH),
65  gArgs.GetArg("-plot-height", DEFAULT_PLOT_HEIGHT)));
66  }
67 
68  benchmark::BenchRunner::RunAll(*printer, evaluations, scaling_factor, regex_filter, is_list_only);
69 
70  ECC_Stop();
71 }
void RandomInit()
Initialize the RNG.
Definition: random.cpp:464
std::string HelpMessageOpt(const std::string &option, const std::string &message)
Format a string to be used as option description in help messages.
Definition: util.cpp:563
void ECC_Start()
Initialize the elliptic curve support.
Definition: key.cpp:291
void ParseParameters(int argc, const char *const argv[])
Definition: util.cpp:454
bool IsArgSet(const std::string &strArg)
Return true if the given argument has been manually set.
Definition: util.cpp:498
#define strprintf
Definition: tinyformat.h:1054
bool GetBoolArg(const std::string &strArg, bool fDefault)
Return boolean argument or default value.
Definition: util.cpp:520
std::string SHA256AutoDetect()
Autodetect the best available SHA256 implementation.
Definition: sha256.cpp:179
int main(int argc, char **argv)
void ECC_Stop()
Deinitialize the elliptic curve support.
Definition: key.cpp:308
static void RunAll(Printer &printer, uint64_t num_evals, double scaling, const std::string &filter, bool is_list_only)
Definition: bench.cpp:97
ArgsManager gArgs
Definition: util.cpp:94
std::string GetArg(const std::string &strArg, const std::string &strDefault)
Return string argument or default value.
Definition: util.cpp:504
bool fPrintToDebugLog
Definition: util.cpp:96
void SetupEnvironment()
Definition: util.cpp:904
std::string HelpMessageGroup(const std::string &message)
Format a string to be used as group of options in help messages.
Definition: util.cpp:559
std::string _(const char *psz)
Translation function: Call Translate signal on UI interface, which returns a boost::optional result...
Definition: util.h:71