HighMap library (C++)
Loading...
Searching...
No Matches
hmap::Timer Class Reference

The Timer class is a singleton that manages multiple Recorders and provides an interface for timing events. More...

#include <timer.hpp>

Public Member Functions

std::map< std::string, Recorder * > get_records () const
 

Static Public Member Functions

static Timerget_instance ()
 Gets the singleton instance of the Timer class.
 
static void Start (const std::string &name)
 Starts a timer for the specified event name.
 
static void Stop (const std::string &name)
 Stops the timer for the specified event name.
 
static void Dump ()
 Dumps the timing information for all recorded events to the console.
 

Detailed Description

The Timer class is a singleton that manages multiple Recorders and provides an interface for timing events.

The Timer class allows you to measure the duration of multiple events by using start and stop commands. Each event is identified by a unique name. The Timer class maintains a collection of these events and their corresponding durations. The class is designed as a singleton, meaning only one instance of Timer will exist throughout the lifetime of the program.

Usage Example:

#include "timer.hpp"
int main() {
// Start timing an event named "step 1"
Timer::Start("step 1");
// Perform some work here...
// Stop timing the event named "step 1"
Timer::Stop("step 1");
// Start and stop another event Timer::Start("step 2");
// Perform more work here...
Timer::Stop("step 2");
// Dump the timing results for all recorded events Timer::Dump();
return 0;
}
static void Stop(const std::string &name)
Stops the timer for the specified event name.
Definition timer.cpp:51
static void Start(const std::string &name)
Starts a timer for the specified event name.
Definition timer.cpp:46

Member Function Documentation

◆ get_instance()

Timer & hmap::Timer::get_instance ( )
static

Gets the singleton instance of the Timer class.

Returns
Timer& Reference to the singleton instance.

◆ Start()

void hmap::Timer::Start ( const std::string &  name)
static

Starts a timer for the specified event name.

Parameters
nameThe name of the event to start timing.

◆ Stop()

void hmap::Timer::Stop ( const std::string &  name)
static

Stops the timer for the specified event name.

Parameters
nameThe name of the event to stop timing.

◆ Dump()

void hmap::Timer::Dump ( )
static

Dumps the timing information for all recorded events to the console.

◆ get_records()

std::map< std::string, Recorder * > hmap::Timer::get_records ( ) const
inline

The documentation for this class was generated from the following files: