From db75317d3174e405589ef90bb221556075547b96 Mon Sep 17 00:00:00 2001 From: Henrik Hautakoski Date: Wed, 29 Jan 2020 09:12:33 +0100 Subject: [PATCH] src/main.cpp: implement benchmark command. --- src/main.cpp | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index a68eed7..a9a46c7 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -30,6 +30,7 @@ #include "WIF.h" #include "ec.h" #include "key_search.h" +#include "benchmark.h" // Command line options. bool option_l33t = false; @@ -81,7 +82,9 @@ void usage(const char *name) { #ifdef HAVE_THREADS << " | --threads=" #endif /* HAVE_THREADS */ - << " ] [ ] ]" + << " ] [ ]" + << " | benchmark [ ]" + << " ]" << std::endl << std::endl; std::cout << " - Output one EOSIO key pair if no arguments are given" << std::endl << std::endl; @@ -105,6 +108,23 @@ void usage(const char *name) { << " Default is what the operating system recomend." #endif /* HAVE_THREADS */ << std::endl; + + std::cout << " Benchmark: " << std::endl + << " performs a benchmark test, generating keys and measuring the time." << std::endl + << std::endl; +} + +void cmd_benchmark(size_t num_keys) { + + struct benchmark_result res; + + std::cout << "Benchmark: Generating " + << num_keys << " keys" << std::endl; + + benchmark(num_keys, &res); + + std::cout << "Result: Took " << res.sec << " seconds, " + << res.kps << " keys per second." << std::endl; } int main(int argc, char **argv) { @@ -164,6 +184,19 @@ int main(int argc, char **argv) { // Pass the rest of argv, argc cmd_search(argc - p, &argv[p]); + } + // Benchmark + else if (!strcmp(argv[p], "benchmark")) { + int num_keys = 1000; + + if (++p < argc) { + num_keys = atoi(argv[p]); + if (num_keys < 1) { + num_keys = 1; + } + } + + cmd_benchmark(num_keys); } else { std::cerr << "Unrecogniced command: " << argv[1] << std::endl; usage(argv[0]);