Skip to content

Commit

Permalink
Benchmark: added more check hashes and a progress indicator
Browse files Browse the repository at this point in the history
  • Loading branch information
SChernykh committed Oct 15, 2020
1 parent 144f9c4 commit 722e468
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 29 deletions.
2 changes: 1 addition & 1 deletion doc/BENCHMARK.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ xmrig --bench=10M
xmrig --bench=1M -a rx/wow
xmrig --bench=10M -a rx/wow
```
This will run 1 or 10 millions RandomX hashes and print the time it took. First two commands use Monero variant (2 MB per thread, best for Zen2/Zen3 CPUs), second two commands use Wownero variant (1 MB per thread, useful for Intel and 1st gen Zen/Zen+ CPUs).
This will run between 1 and 10 million RandomX hashes, depending on `bench` parameter, and print the time it took. First two commands use Monero variant (2 MB per thread, best for Zen2/Zen3 CPUs), second two commands use Wownero variant (1 MB per thread, useful for Intel and 1st gen Zen/Zen+ CPUs).

Checksum of all the hashes will be also printed to check stability of your hardware: if it's green then it's correct, if it's red then there was hardware error during computation. No Internet connection is required for the benchmark.

Expand Down
40 changes: 20 additions & 20 deletions src/backend/common/Workers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include "backend/cpu/CpuWorker.h"
#include "base/io/log/Log.h"
#include "base/io/log/Tags.h"
#include "base/net/stratum/Pool.h"
#include "base/tools/Chrono.h"
#include "base/tools/Object.h"
#include "core/Miner.h"
Expand Down Expand Up @@ -205,32 +206,31 @@ bool xmrig::Workers<T>::tick(uint64_t)
d_ptr->hashrate->add(0, totalHashCount, Chrono::steadyMSecs());
}

if (d_ptr->bench && (benchDone == m_workers.size())) {
const double dt = (benchDoneTime - d_ptr->startTime) / 1000.0;
if (d_ptr->bench) {
Pool::benchProgress = std::min<uint32_t>(static_cast<uint32_t>((totalHashCount * 100U) / d_ptr->bench), 100U);

static uint64_t hashCheck[Algorithm::MAX][2] = {};
hashCheck[Algorithm::RX_0][0] = 0x898B6E0431C28A6BULL;
hashCheck[Algorithm::RX_0][1] = 0xB5231262E2792B26ULL;
hashCheck[Algorithm::RX_WOW][0] = 0x0F3E5400B39EA96AULL;
hashCheck[Algorithm::RX_WOW][1] = 0x0F9E00C5A511C200ULL;
if (benchDone == m_workers.size()) {
const double dt = (benchDoneTime - d_ptr->startTime) / 1000.0;

int k = -1;
uint64_t checkData = 0;

switch (d_ptr->bench) {
case 1000000:
k = 0;
break;
const Algorithm::Id algo = d_ptr->benchAlgo.id();
const uint32_t N = (d_ptr->bench / 1000000) - 1;

case 10000000:
k = 1;
break;
}
if (((algo == Algorithm::RX_0) || (algo == Algorithm::RX_WOW)) && ((d_ptr->bench % 1000000) == 0) && (N < 10)) {
static uint64_t hashCheck[2][10] = {
{ 0x898B6E0431C28A6BULL, 0xEE9468F8B40926BCULL, 0xC2BC5D11724813C0ULL, 0x3A2C7B285B87F941ULL, 0x3B5BD2C3A16B450EULL, 0x5CD0602F20C5C7C4ULL, 0x101DE939474B6812ULL, 0x52B765A1B156C6ECULL, 0x323935102AB6B45CULL, 0xB5231262E2792B26ULL },
{ 0x0F3E5400B39EA96AULL, 0x85944CCFA2752D1FULL, 0x64AFFCAE991811BAULL, 0x3E4D0B836D3B13BAULL, 0xEB7417D621271166ULL, 0x97FFE10C0949FFA5ULL, 0x84CAC0F8879A4BA1ULL, 0xA1B79F031DA2459FULL, 0x9B65226DA873E65DULL, 0x0F9E00C5A511C200ULL },
};

checkData = hashCheck[(algo == Algorithm::RX_0) ? 0 : 1][N];
}

const uint64_t checkData = (k >= 0) ? hashCheck[d_ptr->benchAlgo.id()][k] : 0;
const char* color = checkData ? ((benchData == checkData) ? GREEN_BOLD_S : RED_BOLD_S) : BLACK_BOLD_S;
const char* color = checkData ? ((benchData == checkData) ? GREEN_BOLD_S : RED_BOLD_S) : BLACK_BOLD_S;

LOG_INFO("%s Benchmark finished in %.3f seconds, hash sum = %s%016" PRIX64 CLEAR, Tags::miner(), dt, color, benchData);
return false;
LOG_INFO("%s Benchmark finished in %.3f seconds, hash sum = %s%016" PRIX64 CLEAR, Tags::miner(), dt, color, benchData);
return false;
}
}

return true;
Expand Down
15 changes: 10 additions & 5 deletions src/base/net/stratum/Pool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ const char *Pool::kBenchmark = "benchmark";
const char *Pool::kNicehashHost = "nicehash.com";


uint32_t Pool::benchProgress = 0;


}


Expand Down Expand Up @@ -136,11 +139,13 @@ xmrig::Pool::Pool(const rapidjson::Value &object) :

const char* benchSize = Json::getString(object, kBenchmark, nullptr);
if (benchSize) {
if (strcasecmp(benchSize, "1M") == 0) {
m_benchSize = 1000000;
}
else if (strcasecmp(benchSize, "10M") == 0) {
m_benchSize = 10000000;
std::string s;
for (int i = 1; i <= 10; ++i) {
s = std::to_string(i) + "M";
if (strcasecmp(benchSize, s.c_str()) == 0) {
m_benchSize = i * 1000000;
break;
}
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/base/net/stratum/Pool.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ class Pool
void print() const;
# endif

static uint32_t benchProgress;

private:
enum Flags {
FLAG_ENABLED,
Expand Down
9 changes: 7 additions & 2 deletions src/core/Miner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -304,8 +304,13 @@ class MinerPrivate
}
# endif

LOG_INFO("%s " WHITE_BOLD("speed") " 10s/60s/15m " CYAN_BOLD("%s") CYAN(" %s %s ") CYAN_BOLD("%s") " max " CYAN_BOLD("%s %s"),
Tags::miner(),
char benchProgress[8] = {};
if (Pool::benchProgress) {
sprintf(benchProgress, "%3u%% ", Pool::benchProgress);
}

LOG_INFO("%s %s" WHITE_BOLD("speed") " 10s/60s/15m " CYAN_BOLD("%s") CYAN(" %s %s ") CYAN_BOLD("%s") " max " CYAN_BOLD("%s %s"),
Tags::miner(), benchProgress,
Hashrate::format(speed[0] * scale, num, sizeof(num) / 4),
Hashrate::format(speed[1] * scale, num + 16, sizeof(num) / 4),
Hashrate::format(speed[2] * scale, num + 16 * 2, sizeof(num) / 4), h,
Expand Down
2 changes: 1 addition & 1 deletion src/core/config/usage.h
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ static inline const std::string &usage()
# endif
u += " --pause-on-battery pause mine on battery power\n";
u += " --stress run continuous stress test to check system stability\n";
u += " --bench=N run benchmark in offline mode, N can be 1M or 10M\n";
u += " --bench=N run benchmark in offline mode, N can be between 1M and 10M\n";

return u;
}
Expand Down

0 comments on commit 722e468

Please sign in to comment.