Skip to content

Commit 64699e1

Browse files
committed
include max and min time in chrono
1 parent a27a91e commit 64699e1

2 files changed

Lines changed: 20 additions & 3 deletions

File tree

include/Structure_Helper.h

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -454,10 +454,12 @@ struct Chrono
454454
{
455455
String name = "";
456456
int32_t loopNbr = 0;
457-
static inline bool print = false;
457+
static inline bool print = true;
458458
int32_t loopMax = 0;
459459
unsigned long startTime = 0;
460460
unsigned long elapsedTime = 0;
461+
unsigned long maxTime = 0; // Maximum time reached in a loop
462+
unsigned long minTime = ULONG_MAX; // Minimum time reached in a loop
461463
Chrono(const String &_name, int32_t _nbrLoop) : name(_name), loopMax(_nbrLoop) {};
462464

463465
void Start()
@@ -467,12 +469,25 @@ struct Chrono
467469
{
468470
loopNbr = 0;
469471
elapsedTime = 0;
472+
maxTime = 0;
473+
minTime = ULONG_MAX;
470474
}
471475
};
472476
bool Check()
473477
{
474-
elapsedTime += micros() - startTime;
478+
unsigned long loopTime = micros() - startTime;
479+
elapsedTime += loopTime;
475480
loopNbr++;
481+
482+
// Update min and max times
483+
if (loopTime > maxTime)
484+
{
485+
maxTime = loopTime;
486+
}
487+
if (loopTime < minTime)
488+
{
489+
minTime = loopTime;
490+
}
476491
if (loopNbr >= loopMax)
477492
{
478493
return true;

src/Printer.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,8 +278,10 @@ Format Specifier
278278
if(Chrono::print)
279279
{
280280
int time = (int)(chrono.elapsedTime/chrono.loopNbr);
281+
int maxTime = (int)chrono.maxTime;
282+
int minTime = (int)chrono.minTime;
281283
uint stackSize = uxTaskGetStackHighWaterMark(nullptr);
282-
println("Chrono [%s]: %d µs -- Stack Size: %u", chrono.name.c_str(), time, stackSize);
284+
println("Chrono [%s]: avg=%d µs, max=%d µs, min=%d µs -- Stack Size: %u", chrono.name.c_str(), time, maxTime, minTime, stackSize);
283285
}
284286
//if(Chrono::teleplot)
285287
// teleplot(name,time);

0 commit comments

Comments
 (0)