mirror of
https://git.wownero.com/wownero/wownero.git
synced 2024-08-15 01:03:23 +00:00
perf_timer: rewrite to make it clear there is no division by zero
It could have happened if epee::misc_utils::get_ns_count is buggy, at a push Coverity 182561
This commit is contained in:
parent
c6ea3df0ae
commit
f3f7da624d
1 changed files with 3 additions and 4 deletions
|
@ -49,16 +49,15 @@ namespace
|
|||
#ifdef __x86_64__
|
||||
uint64_t get_ticks_per_ns()
|
||||
{
|
||||
uint64_t t0 = epee::misc_utils::get_ns_count();
|
||||
uint64_t t0 = epee::misc_utils::get_ns_count(), t1;
|
||||
uint64_t r0 = get_tick_count();
|
||||
|
||||
while (1)
|
||||
{
|
||||
uint64_t t = epee::misc_utils::get_ns_count();
|
||||
if (t - t0 > 1*1000000000) break; // work one second
|
||||
t1 = epee::misc_utils::get_ns_count();
|
||||
if (t1 - t0 > 1*1000000000) break; // work one second
|
||||
}
|
||||
|
||||
uint64_t t1 = epee::misc_utils::get_ns_count();
|
||||
uint64_t r1 = get_tick_count();
|
||||
uint64_t tpns256 = 256 * (r1 - r0) / (t1 - t0);
|
||||
return tpns256 ? tpns256 : 1;
|
||||
|
|
Loading…
Reference in a new issue