Loading...
Searching...
No Matches
yoda::ScopedTimer Class Reference

A simple RAII-based timer for benchmarking. More...

#include <yoda.hpp>

Public Types

enum class  Unit { Seconds , Milliseconds , Microseconds }
 Timer resolution units. More...
 

Public Member Functions

 ScopedTimer (std::string label, Unit unit=Unit::Milliseconds)
 Start the timer with a label.
 
 ~ScopedTimer ()
 Stop the timer and print elapsed time.
 
const std::string & label () const
 Get the label for this timer.
 

Detailed Description

A simple RAII-based timer for benchmarking.

Demonstrates nested types, constructors/destructors, and the @test directive.

Test
Verify that elapsed time is non-negative after construction.

Definition at line 244 of file yoda.hpp.

Member Enumeration Documentation

◆ Unit

enum class yoda::ScopedTimer::Unit
strong

Timer resolution units.

Enumerator
Seconds 

Report in seconds.

Milliseconds 

Report in milliseconds.

Microseconds 

Report in microseconds.

Definition at line 247 of file yoda.hpp.

247 {
248 Seconds,
249 Milliseconds,
250 Microseconds
251 };

Constructor & Destructor Documentation

◆ ScopedTimer()

yoda::ScopedTimer::ScopedTimer ( std::string label,
Unit unit = Unit::Milliseconds )
explicit

Start the timer with a label.

Parameters
labelA human-readable name for this timing region.
unitThe resolution to report (default: milliseconds).

References label(), and Milliseconds.

◆ ~ScopedTimer()

yoda::ScopedTimer::~ScopedTimer ( )

Stop the timer and print elapsed time.

Postcondition
The elapsed time has been printed to stdout.

Member Function Documentation

◆ label()

const std::string & yoda::ScopedTimer::label ( ) const
inlinenodiscard

Get the label for this timer.

Definition at line 268 of file yoda.hpp.

268{ return label_; }

Referenced by ScopedTimer().


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