Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for automated benchmarking #54

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 25 additions & 3 deletions cpu-miner.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ static const char *algo_names[] = {
bool opt_debug = false;
bool opt_protocol = false;
static bool opt_benchmark = false;
static uint32_t opt_benchmark_rounds = 0;
bool want_longpoll = true;
bool have_longpoll = false;
bool want_stratum = true;
Expand Down Expand Up @@ -195,6 +196,7 @@ Options:\n\
#endif
"\
--benchmark run in offline benchmark mode\n\
--benchmark-rounds=N quit after N benchmark rounds (default: 0, never)\n\
-c, --config=FILE load a JSON-format configuration file\n\
-V, --version display version information and exit\n\
-h, --help display this help text and exit\n\
Expand All @@ -215,6 +217,7 @@ static struct option const options[] = {
{ "background", 0, NULL, 'B' },
#endif
{ "benchmark", 0, NULL, 1005 },
{ "benchmark-rounds", 1, NULL, 1006 },
{ "cert", 1, NULL, 1001 },
{ "config", 1, NULL, 'c' },
{ "debug", 0, NULL, 'D' },
Expand Down Expand Up @@ -784,12 +787,28 @@ static void *miner_thread(void *userdata)
thr_id, hashes_done, s);
}
if (opt_benchmark && thr_id == opt_n_threads - 1) {
double hashrate = 0.;
static double hashrate = 0.;
static unsigned rounds = 0;

if (!opt_benchmark_rounds) {
hashrate = 0.;
}

for (i = 0; i < opt_n_threads && thr_hashrates[i]; i++)
hashrate += thr_hashrates[i];
if (i == opt_n_threads) {
sprintf(s, hashrate >= 1e6 ? "%.0f" : "%.2f", 1e-3 * hashrate);
applog(LOG_INFO, "Total: %s khash/s", s);
rounds++;

if (!opt_benchmark_rounds) {
sprintf(s, hashrate >= 1e6 ? "%.0f" : "%.2f",
1e-3 * hashrate);
applog(LOG_INFO, "Total: %s khash/s", s);
} else if (opt_benchmark_rounds == rounds) {
sprintf(s, hashrate >= 1e6 ? "%.0f" : "%.2f",
1e-3 * hashrate / rounds);
applog(LOG_INFO, "Total: %s khash/s", s);
exit(0);
}
}
}

Expand Down Expand Up @@ -1163,6 +1182,9 @@ static void parse_arg (int key, char *arg)
free(opt_cert);
opt_cert = strdup(arg);
break;
case 1006:
opt_benchmark_rounds = atoi(arg);
/* Fallthrough, benchmark rounds implies benchmark */
case 1005:
opt_benchmark = true;
want_longpoll = false;
Expand Down