Skip to content

Commit

Permalink
Add a constructor to CalculationTime
Browse files Browse the repository at this point in the history
This to insure we always use properly initialized variable

Also split the asserts, to make it easier to know which part failed
  • Loading branch information
greenscientist committed Feb 21, 2024
1 parent 2bcf11c commit dbf18dd
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
2 changes: 1 addition & 1 deletion include/calculation_time.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace TrRouting
class CalculationTime {

public:

CalculationTime();
//static CalculationTime algorithmCalculationTime;
long long getDurationMicroseconds();
long long getDurationMicrosecondsNoStop();
Expand Down
24 changes: 21 additions & 3 deletions src/calculation_time.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 >(
Expand All @@ -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;
}

Expand All @@ -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;
}

Expand Down

0 comments on commit dbf18dd

Please sign in to comment.