Skip to content

Timer

Abstract base class for measuring execution time and performance metrics. More...

#include "Scripting/Timer.h"

Inherited by CPUTimer, GPUTimer

Public Functions

Name
Timer() =default
Timer(double intervalSeconds, sol::protected_function callback, bool oneShot =false)
Timer(std::string name)<br>Constructor.
virtual~Timer() =default<br>Virtual destructor.
virtual doubleget() =0<br>Retrieves the elapsed time for the most recent interval.
virtual doublegetAverage() =0<br>Retrieves the average time over all measured intervals.
virtual unsigned intgetCounter() const =0<br>Retrieves the number of recorded intervals.
const std::string &getName() const<br>Retrieves the name of the timer.
virtual voidreset() =0<br>Resets the timer, clearing all recorded data.
virtual voidstart(bool sync =false) =0<br>Starts the timer.
virtual voidstop(bool sync =false) =0<br>Stops the timer.
voidtick(double dt)

Protected Attributes

Name
unsigned intcounter <br>Number of recorded intervals.
std::stringname <br>Name of the timer.
GLuint64previousFrameQueryStart
doublepreviousFrameTimeStart <br>Start time of the previous frame.
GLuintquery <br>OpenGL query object for timing.
GLuintqueryStart
GLuintqueryStop <br>OpenGL query objects for timing.
doubletime <br>Time elapsed for the current interval.
doubletimeStart <br>Start time of the current interval.
doubletimeStop <br>Stop time of the current interval.
doubletimeTotal <br>Total accumulated time.

Friends

Name
classChronos

Detailed Description

cpp
class Timer;
class Timer;

Abstract base class for measuring execution time and performance metrics.

The Timer class provides a generic interface for timing operations. Derived classes must implement methods for starting, stopping, and retrieving timing information.

Public Functions Documentation

function Timer

cpp
Timer() =default
Timer() =default

function Timer

cpp
inline Timer(
    double intervalSeconds,
    sol::protected_function callback,
    bool oneShot =false
)
inline Timer(
    double intervalSeconds,
    sol::protected_function callback,
    bool oneShot =false
)

function Timer

cpp
inline Timer(
    std::string name
)
inline Timer(
    std::string name
)

Constructor.

Parameters:

  • name Name of the timer.

function ~Timer

cpp
virtual ~Timer() =default
virtual ~Timer() =default

Virtual destructor.

function get

cpp
virtual double get() =0
virtual double get() =0

Retrieves the elapsed time for the most recent interval.

Return: The elapsed time in seconds.

Reimplemented by: CPUTimer::get, GPUTimer::get

function getAverage

cpp
virtual double getAverage() =0
virtual double getAverage() =0

Retrieves the average time over all measured intervals.

Return: The average time in seconds.

Reimplemented by: CPUTimer::getAverage, GPUTimer::getAverage

function getCounter

cpp
virtual unsigned int getCounter() const =0
virtual unsigned int getCounter() const =0

Retrieves the number of recorded intervals.

Return: The interval count.

Reimplemented by: CPUTimer::getCounter, GPUTimer::getCounter

function getName

cpp
inline const std::string & getName() const
inline const std::string & getName() const

Retrieves the name of the timer.

Return: A reference to the timer name.

function reset

cpp
virtual void reset() =0
virtual void reset() =0

Resets the timer, clearing all recorded data.

Reimplemented by: CPUTimer::reset, GPUTimer::reset

function start

cpp
virtual void start(
    bool sync =false
) =0
virtual void start(
    bool sync =false
) =0

Starts the timer.

Parameters:

  • sync Whether to synchronize with external operations before starting.

Reimplemented by: CPUTimer::start, GPUTimer::start

function stop

cpp
virtual void stop(
    bool sync =false
) =0
virtual void stop(
    bool sync =false
) =0

Stops the timer.

Parameters:

  • sync Whether to synchronize with external operations before stopping.

Reimplemented by: CPUTimer::stop, GPUTimer::stop

function tick

cpp
inline void tick(
    double dt
)
inline void tick(
    double dt
)

Parameters:

  • dt in seconds

Protected Attributes Documentation

variable counter

cpp
unsigned int counter {0};
unsigned int counter {0};

Number of recorded intervals.

variable name

cpp
std::string name;
std::string name;

Name of the timer.

variable previousFrameQueryStart

cpp
GLuint64 previousFrameQueryStart {0};
GLuint64 previousFrameQueryStart {0};

variable previousFrameTimeStart

cpp
double previousFrameTimeStart {0};
double previousFrameTimeStart {0};

Start time of the previous frame.

variable query

cpp
GLuint query {0};
GLuint query {0};

OpenGL query object for timing.

variable queryStart

cpp
GLuint queryStart {0};
GLuint queryStart {0};

variable queryStop

cpp
GLuint queryStop {0};
GLuint queryStop {0};

OpenGL query objects for timing.

variable time

cpp
double time {0};
double time {0};

Time elapsed for the current interval.

variable timeStart

cpp
double timeStart {0};
double timeStart {0};

Start time of the current interval.

variable timeStop

cpp
double timeStop {0};
double timeStop {0};

Stop time of the current interval.

variable timeTotal

cpp
double timeTotal {0};
double timeTotal {0};

Total accumulated time.

Friends

friend Chronos

cpp
friend class Chronos(
    Chronos 
);
friend class Chronos(
    Chronos 
);

Updated on 2025-05-31 at 12:55:30 +0000