From d08b2e27a57c27a71ae936b6377ed915ec58b902 Mon Sep 17 00:00:00 2001 From: Dmytro Bogovych Date: Mon, 14 Oct 2024 08:44:33 +0300 Subject: [PATCH] - find difference between 'struct timeval' --- src/engine/helper/HL_Sync.cpp | 7 +++++++ src/engine/helper/HL_Sync.h | 1 + 2 files changed, 8 insertions(+) diff --git a/src/engine/helper/HL_Sync.cpp b/src/engine/helper/HL_Sync.cpp index 9344d1d3..9e4671c5 100644 --- a/src/engine/helper/HL_Sync.cpp +++ b/src/engine/helper/HL_Sync.cpp @@ -127,6 +127,13 @@ int64_t chronox::getDelta(const timespec& a, const timespec& b) return ms_a - ms_b; } +int64_t chronox::getDelta(const timeval& a, const timeval& b) +{ + int64_t diff_seconds = a.tv_sec - b.tv_sec; + int64_t diff_microseconds = a.tv_usec - b.tv_usec; + return diff_seconds * 1000 + diff_microseconds / 1000; +} + chronox::ExecutionTime::ExecutionTime() { mStart = chronox::getTimestamp(); diff --git a/src/engine/helper/HL_Sync.h b/src/engine/helper/HL_Sync.h index fbebf184..b30fc1ca 100644 --- a/src/engine/helper/HL_Sync.h +++ b/src/engine/helper/HL_Sync.h @@ -64,6 +64,7 @@ public: // Returns difference between timestamps in milliseconds static int64_t getDelta(const timespec& a, const timespec& b); + static int64_t getDelta(const timeval& a, const timeval& b); class ExecutionTime {