Skip to content
This repository was archived by the owner on Apr 24, 2022. It is now read-only.

Commit f529084

Browse files
committedSep 3, 2018
Minor optimization and cleanup
- Delete unnecessarily maintained variable - Allow the compiler the option to inline time critical method.
1 parent 54c3489 commit f529084

File tree

2 files changed

+12
-15
lines changed

2 files changed

+12
-15
lines changed
 

‎libethcore/Miner.cpp

-13
Original file line numberDiff line numberDiff line change
@@ -33,19 +33,6 @@ bool Miner::s_exit = false;
3333

3434
bool Miner::s_noeval = false;
3535

36-
void Miner::updateHashRate(uint64_t n)
37-
{
38-
m_hashCounter = n;
39-
std::chrono::steady_clock::time_point t = std::chrono::steady_clock::now();
40-
float us = float(std::chrono::duration_cast<std::chrono::microseconds>(t - m_hashTime).count());
41-
m_hashTime = t;
42-
43-
float hr = 0;
44-
if (us)
45-
hr = float(m_hashCounter) / (us / 1000000.0);
46-
m_hashRate.store(hr, std::memory_order_relaxed);
47-
}
48-
4936
std::ostream& operator<<(std::ostream& os, HwMonitor _hw)
5037
{
5138
os << _hw.tempC << "C " << _hw.fanP << "%";

‎libethcore/Miner.h

+12-2
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,18 @@ class Miner : public Worker
286286
return m_work;
287287
}
288288

289-
void updateHashRate(uint64_t _n);
289+
inline void updateHashRate(uint64_t _n)
290+
{
291+
using namespace std::chrono;
292+
steady_clock::time_point t = steady_clock::now();
293+
auto us = duration_cast<microseconds>(t - m_hashTime).count();
294+
m_hashTime = t;
295+
296+
float hr = 0.0;
297+
if (us)
298+
hr = (float(_n) * 1.0e6f) / us;
299+
m_hashRate.store(hr, std::memory_order_relaxed);
300+
}
290301

291302
static unsigned s_dagLoadMode;
292303
static unsigned s_dagLoadIndex;
@@ -305,7 +316,6 @@ class Miner : public Worker
305316
WorkPackage m_work;
306317
mutable Mutex x_work;
307318
std::chrono::steady_clock::time_point m_hashTime = std::chrono::steady_clock::now();
308-
uint64_t m_hashCounter = 0;
309319
std::atomic<float> m_hashRate = {0.0};
310320
};
311321

0 commit comments

Comments
 (0)
This repository has been archived.