aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormoneromooo-monero <moneromooo-monero@users.noreply.github.com>2018-02-02 16:05:06 +0000
committermoneromooo-monero <moneromooo-monero@users.noreply.github.com>2018-02-02 16:06:36 +0000
commitf3f7da624de546c8f4e6b236d364377b19c49d78 (patch)
tree54d0b09728402ac3a794e80467c4d44d07c8590b
parentperformance_tests: remove add_arg call stray extra param (diff)
downloadmonero-f3f7da624de546c8f4e6b236d364377b19c49d78.tar.xz
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
-rw-r--r--src/common/perf_timer.cpp7
1 files changed, 3 insertions, 4 deletions
diff --git a/src/common/perf_timer.cpp b/src/common/perf_timer.cpp
index 41e23130d..16abdfd99 100644
--- a/src/common/perf_timer.cpp
+++ b/src/common/perf_timer.cpp
@@ -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;