From 0f3d2788cea9515770f1d80a216315ebc1b099ee Mon Sep 17 00:00:00 2001 From: Yannick Brosseau Date: Wed, 21 Feb 2024 10:44:53 -0500 Subject: [PATCH] Add a constructor to CalculationTime This to insure we always use properly initialized variable Also split the asserts, to make it easier to know which part failed --- include/calculation_time.hpp | 2 +- src/calculation_time.cpp | 24 +++++++++++++++++++++--- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/include/calculation_time.hpp b/include/calculation_time.hpp index d49c6d4c..29bea0da 100644 --- a/include/calculation_time.hpp +++ b/include/calculation_time.hpp @@ -10,7 +10,7 @@ namespace TrRouting class CalculationTime { public: - + CalculationTime(); //static CalculationTime algorithmCalculationTime; long long getDurationMicroseconds(); long long getDurationMicrosecondsNoStop(); diff --git a/src/calculation_time.cpp b/src/calculation_time.cpp index 6d3882a7..dc47140e 100644 --- a/src/calculation_time.cpp +++ b/src/calculation_time.cpp @@ -5,6 +5,15 @@ namespace TrRouting { + CalculationTime::CalculationTime() : + startEpoch(0), + startStepEpoch(0), + endEpoch(0), + endStepEpoch(0), + calculationEpoch() { + //TODO Should we call start() on construction ?? + } + long long CalculationTime::getEpoch() { calculationEpoch = std::chrono::duration_cast< std::chrono::microseconds >( @@ -25,14 +34,20 @@ namespace TrRouting long long CalculationTime::getDurationMicroseconds() { - assert(startEpoch && endEpoch && startEpoch >= 0 && endEpoch >= 0 && endEpoch >= startEpoch); + assert(startEpoch && endEpoch); + assert(startEpoch >= 0); + assert(endEpoch >= 0); + assert(endEpoch >= startEpoch); return endEpoch - startEpoch; } long long CalculationTime::getDurationMicrosecondsNoStop() { long long actualEpoch {getEpoch()}; - assert(startEpoch && actualEpoch && startEpoch >= 0 && actualEpoch >= 0 && actualEpoch >= startEpoch); + assert(startEpoch && actualEpoch); + assert(startEpoch >= 0); + assert(actualEpoch >= 0); + assert(actualEpoch >= startEpoch); return actualEpoch - startEpoch; } @@ -48,7 +63,10 @@ namespace TrRouting long long CalculationTime::getStepDurationMicroseconds() { - assert(startStepEpoch && endStepEpoch && startStepEpoch >= 0 && endStepEpoch >= 0 && endStepEpoch >= startStepEpoch); + assert(startStepEpoch && endStepEpoch); + assert(startStepEpoch >= 0); + assert(endStepEpoch >= 0); + assert(endStepEpoch >= startStepEpoch); return endStepEpoch - startStepEpoch; }