NetBurner 3.5.6
PDF Version
Stopwatch Timer

Classes

class  StopWatch
 High-resolution stopwatch timer for precise event timing and performance measurement. More...
 

Detailed Description

#include< stopwatch.h>


The StopWatch class provides high-resolution timing capabilities for measuring code execution time, profiling performance, and timing events with precision beyond the standard RTOS tick resolution.

Features

Basic Usage

StopWatch myStopwatch;
myStopwatch.Start();
for (volatile int i = 0; i < numLoop; i++)
{
count++;
}
myStopwatch.Stop();
unsigned long long elapsed = myStopwatch.GetTime();
double seconds = myStopwatch.Convert(elapsed);
printf("Elapsed time: %f seconds\n", seconds);
High-resolution stopwatch timer for precise event timing and performance measurement.
Definition stopwatch.h:138
double Convert(unsigned long long ticks)
Convert timer ticks to seconds.
unsigned long long GetTime()
Get the current elapsed time without stopping the timer.
void Start(bool clear_count=false)
Start or resume the stopwatch timer.
unsigned long long Stop()
Stop the stopwatch and return elapsed time.

Advanced Usage - Cumulative Timing

StopWatch timer;
// Time multiple operations cumulatively
timer.Start();
DoOperation1();
timer.Stop();
// Continue timing without clearing
timer.Start(); // Continues from previous elapsed time
DoOperation2();
timer.Stop();
double totalTime = timer.Convert(timer.GetTime());
printf("Total time for both operations: %f seconds\n", totalTime);

Timing Without Stopping

StopWatch timer;
timer.Start();
while (processing)
{
DoWork();
// Check elapsed time without stopping
unsigned long long current = timer.GetTime();
if (current > MAX_ALLOWED_TIME)
{
printf("Warning: Operation taking too long!\n");
break;
}
}
timer.Stop();

Timer Resolution

StopWatch timer;
double resolution = timer.CountResolution();
printf("Timer resolution: %f seconds per tick\n", resolution);
Note
On platforms with dedicated RTOS timers, the timer_number parameter in the constructor can be omitted and the system will automatically allocate an appropriate timer.
The StopWatch maintains cumulative time across Start/Stop cycles unless explicitly cleared with Clear() or Start(true).
See also
Interval Timer For periodic timing and callbacks
High Resolution Delay Timer For precise delays
OSTimeDly() For RTOS-based delays