Skip to content

Instantly share code, notes, and snippets.

@vasilvestre
Last active November 14, 2018 15:27
Show Gist options
  • Save vasilvestre/1399ca951ac584a40ff995ca39cd1b72 to your computer and use it in GitHub Desktop.
Save vasilvestre/1399ca951ac584a40ff995ca39cd1b72 to your computer and use it in GitHub Desktop.
c++ hash speed of program
class Benchmark
{
private:
bool started = false;
bool benched = false;
float functionCalls = 0;
std::chrono::high_resolution_clock::time_point startHash;
std::chrono::high_resolution_clock::time_point startBenchmark;
public:
void
incrementHashCount()
{
if (!this->started)
{
this->started = true;
this->startHash = std::chrono::high_resolution_clock::now();
}
this->functionCalls++;
if (this->functionCalls == 1000000)
{
this->functionCalls = 0;
std::chrono::high_resolution_clock::time_point endHash = std::chrono::high_resolution_clock::now();
double timeFor1MCalls = std::chrono::duration_cast<std::chrono::milliseconds>(endHash - startHash).count();
startHash = std::chrono::high_resolution_clock::now();
long callsSecond = long((1000000 / (timeFor1MCalls / 1000)));
std::cout << "Puissance de l'ensemble des threads : " << callsSecond / 1000 << "MH/s" << std::endl;
}
};
}
int
main(int argc, char **argv)
{
auto *benchmark = new Benchmark();
while (!signal(SIGINT, {}) && !done)
{
benchmark->incrementHashCount();
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment