From 81fd04a2087f1ce3a65cb2a3597e77d2b737f55c Mon Sep 17 00:00:00 2001 From: Tanguy Pruvot Date: Sun, 22 Feb 2015 11:27:12 +0000 Subject: [PATCH] hashrate: Remove some extra units and allow 4 digits to keep current X11 output (sample: 2950.01 kH/s) --- ccminer.cpp | 6 +++--- util.cpp | 41 +++++++++-------------------------------- 2 files changed, 12 insertions(+), 35 deletions(-) diff --git a/ccminer.cpp b/ccminer.cpp index 196e958..313779c 100644 --- a/ccminer.cpp +++ b/ccminer.cpp @@ -528,7 +528,7 @@ static void calc_diff(struct work *work, int known) static int share_result(int result, const char *reason) { - char s[345]; + char s[32] = { 0 }; double hashrate = 0.; pthread_mutex_lock(&stats_lock); @@ -542,8 +542,8 @@ static int share_result(int result, const char *reason) global_hashrate = llround(hashrate); - sprintf(s, hashrate >= 1e6 ? "%.0f" : "%.2f", 1e-3 * hashrate); - applog(LOG_NOTICE, "accepted: %lu/%lu (%.2f%%), %s khash/s %s", + format_hashrate(hashrate, s); + applog(LOG_NOTICE, "accepted: %lu/%lu (%.2f%%), %s %s", accepted_count, accepted_count + rejected_count, 100. * accepted_count / (accepted_count + rejected_count), diff --git a/util.cpp b/util.cpp index 0ae77ef..9056d16 100644 --- a/util.cpp +++ b/util.cpp @@ -175,54 +175,31 @@ void get_defconfig_path(char *out, size_t bufsize, char *argv0) void format_hashrate(double hashrate, char *output) { - char prefix; + char prefix = '\0'; - if (hashrate < 1e3) - prefix = ' '; - else if (hashrate < 1e6) - { + if (hashrate < 10000) { + // nop + } + else if (hashrate < 1e7) { prefix = 'k'; hashrate *= 1e-3; } - else if (hashrate < 1e9) - { + else if (hashrate < 1e10) { prefix = 'M'; hashrate *= 1e-6; } - else if (hashrate < 1e12) - { + else if (hashrate < 1e13) { prefix = 'G'; hashrate *= 1e-9; } - else if (hashrate < 1e15) - { + else { prefix = 'T'; hashrate *= 1e-12; } - else if (hashrate < 1e18) - { - prefix = 'P'; - hashrate *= 1e-15; - } - else if (hashrate < 1e21) - { - prefix = 'E'; - hashrate *= 1e-18; - } - else if (hashrate < 1e24) - { - prefix = 'Z'; - hashrate *= 1e-21; - } - else - { - prefix = 'Y'; - hashrate *= 1e-24; - } sprintf( output, - prefix == ' ' ? "%.0f%cH/s" : "%.2f %cH/s", + prefix ? "%.2f %cH/s" : "%.2f H/s%c", hashrate, prefix ); }