From f9ab781df1d2cac252c4b6516dded7724d7527fd Mon Sep 17 00:00:00 2001 From: enWILLYado Date: Thu, 1 Mar 2018 23:06:59 +0100 Subject: [PATCH] Update hashrate time Use the modern chrono lib to get the hashrate time --- src/workers/Hashrate.cpp | 12 +++++++++++- src/workers/Worker.cpp | 14 ++++++++++++-- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/src/workers/Hashrate.cpp b/src/workers/Hashrate.cpp index 95623ff3..247c36ee 100644 --- a/src/workers/Hashrate.cpp +++ b/src/workers/Hashrate.cpp @@ -22,8 +22,13 @@ */ #ifndef _WIN32 +#if __cplusplus <= 199711L #include #else +#include +#define USE_CHRONO +#endif +#else #define WIN32_LEAN_AND_MEAN #include #include // portable: uint64_t MSVC: __int64 @@ -114,9 +119,14 @@ double Hashrate::calc(size_t ms) const double Hashrate::calc(size_t threadId, size_t ms) const { +#ifdef USE_CHRONO + using namespace std::chrono; + const uint64_t now = time_point_cast(high_resolution_clock::now()).time_since_epoch().count(); +#else struct timeval tp; gettimeofday(&tp, NULL); - uint64_t now = tp.tv_sec * 1000 + tp.tv_usec / 1000; + const uint64_t now = tp.tv_sec * 1000 + tp.tv_usec / 1000; +#endif uint64_t earliestHashCount = 0; uint64_t earliestStamp = 0; diff --git a/src/workers/Worker.cpp b/src/workers/Worker.cpp index 638704a9..bf7c4fdf 100644 --- a/src/workers/Worker.cpp +++ b/src/workers/Worker.cpp @@ -28,8 +28,13 @@ #include "workers/Worker.h" #ifndef _WIN32 +#if __cplusplus <= 199711L #include #else +#include +#define USE_CHRONO +#endif +#else #define WIN32_LEAN_AND_MEAN #include #include // portable: uint64_t MSVC: __int64 @@ -82,10 +87,15 @@ Worker::~Worker() void Worker::storeStats() { +#ifdef USE_CHRONO + using namespace std::chrono; + const uint64_t now = time_point_cast(high_resolution_clock::now()).time_since_epoch().count(); +#else struct timeval tp; gettimeofday(&tp, NULL); - uint64_t timestamp = tp.tv_sec * 1000 + tp.tv_usec / 1000; + const uint64_t now = tp.tv_sec * 1000 + tp.tv_usec / 1000; +#endif m_hashCount = m_count; - m_timestamp = timestamp; + m_timestamp = now; }