Changeset View
Changeset View
Standalone View
Standalone View
src/bench/bench_bitcoin.cpp
// Copyright (c) 2015-2019 The Bitcoin Core developers | // Copyright (c) 2015-2019 The Bitcoin Core developers | ||||
// Distributed under the MIT software license, see the accompanying | // Distributed under the MIT software license, see the accompanying | ||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | // file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
#include <bench/bench.h> | #include <bench/bench.h> | ||||
#include <crypto/sha256.h> | #include <crypto/sha256.h> | ||||
#include <key.h> | #include <key.h> | ||||
#include <util/strencodings.h> | #include <util/strencodings.h> | ||||
#include <util/system.h> | #include <util/system.h> | ||||
#include <validation.h> | |||||
#include <memory> | #include <memory> | ||||
const std::function<std::string(const char *)> G_TRANSLATION_FUN = nullptr; | |||||
static const int64_t DEFAULT_BENCH_EVALUATIONS = 5; | static const int64_t DEFAULT_BENCH_EVALUATIONS = 5; | ||||
static const char *DEFAULT_BENCH_FILTER = ".*"; | static const char *DEFAULT_BENCH_FILTER = ".*"; | ||||
static const char *DEFAULT_BENCH_SCALING = "1.0"; | static const char *DEFAULT_BENCH_SCALING = "1.0"; | ||||
static const char *DEFAULT_BENCH_PRINTER = "console"; | static const char *DEFAULT_BENCH_PRINTER = "console"; | ||||
static const char *DEFAULT_PLOT_PLOTLYURL = | static const char *DEFAULT_PLOT_PLOTLYURL = | ||||
"https://cdn.plot.ly/plotly-latest.min.js"; | "https://cdn.plot.ly/plotly-latest.min.js"; | ||||
static const int64_t DEFAULT_PLOT_WIDTH = 1024; | static const int64_t DEFAULT_PLOT_WIDTH = 1024; | ||||
static const int64_t DEFAULT_PLOT_HEIGHT = 768; | static const int64_t DEFAULT_PLOT_HEIGHT = 768; | ||||
Show All 39 Lines | gArgs.AddArg( | ||||
strprintf("Plot height in pixel (default: %u)", DEFAULT_PLOT_HEIGHT), | strprintf("Plot height in pixel (default: %u)", DEFAULT_PLOT_HEIGHT), | ||||
false, OptionsCategory::OPTIONS); | false, OptionsCategory::OPTIONS); | ||||
// Hidden | // Hidden | ||||
gArgs.AddArg("-h", "", false, OptionsCategory::HIDDEN); | gArgs.AddArg("-h", "", false, OptionsCategory::HIDDEN); | ||||
gArgs.AddArg("-help", "", false, OptionsCategory::HIDDEN); | gArgs.AddArg("-help", "", false, OptionsCategory::HIDDEN); | ||||
} | } | ||||
static fs::path SetDataDir() { | |||||
fs::path ret = | |||||
fs::temp_directory_path() / "bench_bitcoin" / fs::unique_path(); | |||||
fs::create_directories(ret); | |||||
gArgs.ForceSetArg("-datadir", ret.string()); | |||||
return ret; | |||||
} | |||||
int main(int argc, char **argv) { | int main(int argc, char **argv) { | ||||
SetupBenchArgs(); | SetupBenchArgs(); | ||||
std::string error; | std::string error; | ||||
if (!gArgs.ParseParameters(argc, argv, error)) { | if (!gArgs.ParseParameters(argc, argv, error)) { | ||||
fprintf(stderr, "Error parsing command line arguments: %s\n", | fprintf(stderr, "Error parsing command line arguments: %s\n", | ||||
error.c_str()); | error.c_str()); | ||||
return EXIT_FAILURE; | return EXIT_FAILURE; | ||||
} | } | ||||
if (HelpRequested(gArgs)) { | if (HelpRequested(gArgs)) { | ||||
std::cout << gArgs.GetHelpMessage(); | std::cout << gArgs.GetHelpMessage(); | ||||
return EXIT_SUCCESS; | return EXIT_SUCCESS; | ||||
} | } | ||||
// Set the datadir after parsing the bench options | |||||
const fs::path bench_datadir{SetDataDir()}; | |||||
SHA256AutoDetect(); | |||||
ECC_Start(); | |||||
SetupEnvironment(); | |||||
int64_t evaluations = gArgs.GetArg("-evals", DEFAULT_BENCH_EVALUATIONS); | int64_t evaluations = gArgs.GetArg("-evals", DEFAULT_BENCH_EVALUATIONS); | ||||
std::string regex_filter = gArgs.GetArg("-filter", DEFAULT_BENCH_FILTER); | std::string regex_filter = gArgs.GetArg("-filter", DEFAULT_BENCH_FILTER); | ||||
std::string scaling_str = gArgs.GetArg("-scaling", DEFAULT_BENCH_SCALING); | std::string scaling_str = gArgs.GetArg("-scaling", DEFAULT_BENCH_SCALING); | ||||
bool is_list_only = gArgs.GetBoolArg("-list", false); | bool is_list_only = gArgs.GetBoolArg("-list", false); | ||||
double scaling_factor; | double scaling_factor; | ||||
if (!ParseDouble(scaling_str, &scaling_factor)) { | if (!ParseDouble(scaling_str, &scaling_factor)) { | ||||
fprintf(stderr, "Error parsing scaling factor as double: %s\n", | fprintf(stderr, "Error parsing scaling factor as double: %s\n", | ||||
Show All 9 Lines | if ("plot" == printer_arg) { | ||||
gArgs.GetArg("-plot-plotlyurl", DEFAULT_PLOT_PLOTLYURL), | gArgs.GetArg("-plot-plotlyurl", DEFAULT_PLOT_PLOTLYURL), | ||||
gArgs.GetArg("-plot-width", DEFAULT_PLOT_WIDTH), | gArgs.GetArg("-plot-width", DEFAULT_PLOT_WIDTH), | ||||
gArgs.GetArg("-plot-height", DEFAULT_PLOT_HEIGHT))); | gArgs.GetArg("-plot-height", DEFAULT_PLOT_HEIGHT))); | ||||
} | } | ||||
benchmark::BenchRunner::RunAll(*printer, evaluations, scaling_factor, | benchmark::BenchRunner::RunAll(*printer, evaluations, scaling_factor, | ||||
regex_filter, is_list_only); | regex_filter, is_list_only); | ||||
fs::remove_all(bench_datadir); | |||||
ECC_Stop(); | |||||
return EXIT_SUCCESS; | return EXIT_SUCCESS; | ||||
} | } |