implement a basic hash-per-second display
This commit is contained in:
parent
e8cdc4e41a
commit
4629f99495
|
@ -23,6 +23,7 @@ namespace swbf {
|
||||||
std::uint32_t threadIndex;
|
std::uint32_t threadIndex;
|
||||||
std::string codeString;
|
std::string codeString;
|
||||||
std::uint32_t codeHash;
|
std::uint32_t codeHash;
|
||||||
|
std::uint32_t hashRate;
|
||||||
bool done = false;
|
bool done = false;
|
||||||
|
|
||||||
/// The matched codes for this thread.
|
/// The matched codes for this thread.
|
||||||
|
@ -31,8 +32,8 @@ namespace swbf {
|
||||||
|
|
||||||
void DisplayProgress() {
|
void DisplayProgress() {
|
||||||
if(!done)
|
if(!done)
|
||||||
swbf::fprint(stdout, "{}Thread {:2}: Trying code {}{} {}({:08x}){}", swbf::ansi::Line(threadIndex), threadIndex,
|
swbf::fprint(stdout, "{}Thread {:2}: Trying code {}{} {}({:08x}, {} hps){}", swbf::ansi::Line(threadIndex), threadIndex,
|
||||||
swbf::ansi::Color(172), codeString, swbf::ansi::Color(166), codeHash, swbf::ansi::Reset());
|
swbf::ansi::Color(172), codeString, swbf::ansi::Color(166), codeHash, hashRate, swbf::ansi::Reset());
|
||||||
else {
|
else {
|
||||||
swbf::fprint(stdout, "{}{}Thread {:2}: {}Finished!{}", swbf::ansi::Line(threadIndex), swbf::ansi::ResetLine(), threadIndex,
|
swbf::fprint(stdout, "{}{}Thread {:2}: {}Finished!{}", swbf::ansi::Line(threadIndex), swbf::ansi::ResetLine(), threadIndex,
|
||||||
swbf::ansi::Color(172), swbf::ansi::Reset());
|
swbf::ansi::Color(172), swbf::ansi::Reset());
|
||||||
|
@ -79,6 +80,8 @@ namespace swbf {
|
||||||
|
|
||||||
/// Public-facing driver function - the thread pool runs this.
|
/// Public-facing driver function - the thread pool runs this.
|
||||||
void BruteforceWorker::Bruteforce(char prefix) {
|
void BruteforceWorker::Bruteforce(char prefix) {
|
||||||
|
start = Clock::now();
|
||||||
|
|
||||||
if(options.exact) {
|
if(options.exact) {
|
||||||
BruteforceForLength(prefix, options.startLength);
|
BruteforceForLength(prefix, options.startLength);
|
||||||
} else {
|
} else {
|
||||||
|
@ -102,16 +105,26 @@ namespace swbf {
|
||||||
if(hash == options.targetHash)
|
if(hash == options.targetHash)
|
||||||
DisplayData().matches.push_back(test_buffer);
|
DisplayData().matches.push_back(test_buffer);
|
||||||
|
|
||||||
|
numChecked++;
|
||||||
|
|
||||||
CopyDisplayData();
|
CopyDisplayData();
|
||||||
|
|
||||||
if(!NextCode(test_buffer, 1))
|
if(!NextCode(test_buffer, 1))
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
now = Clock::now();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void BruteforceWorker::CopyDisplayData() {
|
void BruteforceWorker::CopyDisplayData() {
|
||||||
std::memcpy(DisplayData().codeString.data(), test_buffer.data(), test_buffer.length());
|
std::memcpy(DisplayData().codeString.data(), test_buffer.data(), test_buffer.length());
|
||||||
DisplayData().codeHash = hash;
|
DisplayData().codeHash = hash;
|
||||||
|
|
||||||
|
if(std::chrono::duration_cast<std::chrono::seconds>(now - start).count() >= 1) {
|
||||||
|
DisplayData().hashRate = numChecked;
|
||||||
|
numChecked = 0;
|
||||||
|
start = Clock::now();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ThreadInfoData& BruteforceWorker::DisplayData() {
|
ThreadInfoData& BruteforceWorker::DisplayData() {
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <chrono>
|
||||||
|
|
||||||
namespace swbf {
|
namespace swbf {
|
||||||
constexpr static auto MAX_CODE_LENGTH = 8;
|
constexpr static auto MAX_CODE_LENGTH = 8;
|
||||||
|
@ -39,6 +40,11 @@ namespace swbf {
|
||||||
unsigned threadIndex;
|
unsigned threadIndex;
|
||||||
std::string test_buffer;
|
std::string test_buffer;
|
||||||
std::uint32_t hash;
|
std::uint32_t hash;
|
||||||
|
|
||||||
|
using Clock = std::chrono::steady_clock;
|
||||||
|
Clock::time_point now;
|
||||||
|
Clock::time_point start;
|
||||||
|
std::uint32_t numChecked;
|
||||||
};
|
};
|
||||||
|
|
||||||
/// returns true when all threads finished
|
/// returns true when all threads finished
|
||||||
|
|
Loading…
Reference in New Issue