aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib
diff options
context:
space:
mode:
authorJack Lloyd <[email protected]>2018-12-23 14:20:43 -0500
committerJack Lloyd <[email protected]>2018-12-23 14:20:43 -0500
commit935506524f7bcf52d10662a08a4e3e1376cd180a (patch)
treef643b646d040458a833d98b4db89c878eb986604 /src/lib
parent3d076b1ddc24fdd165e14d5a417408b415b1c26d (diff)
In Timer, grab CPU clock first
Reading the system timestamp first causes every event to get a few hundred cycles tacked onto it. Only mattered when the thing being tested was very fast.
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/utils/timer.cpp18
1 files changed, 9 insertions, 9 deletions
diff --git a/src/lib/utils/timer.cpp b/src/lib/utils/timer.cpp
index 5d64e63fb..634cd83f5 100644
--- a/src/lib/utils/timer.cpp
+++ b/src/lib/utils/timer.cpp
@@ -15,6 +15,15 @@ void Timer::stop()
{
if(m_timer_start)
{
+ if(m_cpu_cycles_start != 0)
+ {
+ uint64_t cycles_taken = Timer::get_cpu_cycle_counter() - m_cpu_cycles_start;
+ if(cycles_taken > 0)
+ {
+ m_cpu_cycles_used += static_cast<size_t>(cycles_taken * m_clock_cycle_ratio);
+ }
+ }
+
const uint64_t now = Timer::get_system_timestamp_ns();
if(now > m_timer_start)
@@ -23,15 +32,6 @@ void Timer::stop()
m_time_used += dur;
- if(m_cpu_cycles_start != 0)
- {
- uint64_t cycles_taken = Timer::get_cpu_cycle_counter() - m_cpu_cycles_start;
- if(cycles_taken > 0)
- {
- m_cpu_cycles_used += static_cast<size_t>(cycles_taken * m_clock_cycle_ratio);
- }
- }
-
if(m_event_count == 0)
{
m_min_time = m_max_time = dur;