Improved microbenchmarking with multiple features.
[bitcoinplatinum.git] / src / bench / bench_bitcoin.cpp
blob5e0432f0eeb6ff67a3f681b7cb9441371158d717
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.
5 #include <bench/bench.h>
7 #include <crypto/sha256.h>
8 #include <key.h>
9 #include <validation.h>
10 #include <util.h>
11 #include <random.h>
13 #include <boost/lexical_cast.hpp>
15 #include <memory>
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;
25 int
26 main(int argc, char** argv)
28 gArgs.ParseParameters(argc, argv);
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));
42 return 0;
45 SHA256AutoDetect();
46 RandomInit();
47 ECC_Start();
48 SetupEnvironment();
49 fPrintToDebugLog = false; // don't want to write to debug.log file
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);
56 double scaling_factor = boost::lexical_cast<double>(scaling_str);
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)));
68 benchmark::BenchRunner::RunAll(*printer, evaluations, scaling_factor, regex_filter, is_list_only);
70 ECC_Stop();