Template Numerical Library version\ main:f17d0c8
Loading...
Searching...
No Matches
Public Member Functions | List of all members
TNL::PerformanceCounters Struct Reference

Performance counter for measuring CPU cycles. More...

#include <TNL/PerformanceCounters.h>

Public Member Functions

 PerformanceCounters ()
 Constructor with no parameters.
 
unsigned long long int getCPUCycles () const
 Returns the number of CPU cycles (machine cycles) elapsed on this timer.
 
void reset ()
 Reset counters.
 
void start ()
 Starts counters.
 
void stop ()
 Stops (pauses) the counters but do not set them to zeros.
 
bool writeLog (Logger &logger, int logLevel=0) const
 Writes a record into the logger.
 

Detailed Description

Performance counter for measuring CPU cycles.

The counter can be paused by calling stop and start methods and reseted by calling reset.

Example
#include <iostream>
#include <chrono>
#include <thread>
#include <TNL/PerformanceCounters.h>
int
main()
{
const int milliseconds = 0.5e3;
TNL::PerformanceCounters performanceCounters;
performanceCounters.start();
performanceCounters.stop();
std::cout << "Elapsed CPU cycles: " << performanceCounters.getCPUCycles() << std::endl;
performanceCounters.reset();
std::cout << "CPU cycles after reset: " << performanceCounters.getCPUCycles() << std::endl;
}
T endl(T... args)
T sleep_for(T... args)
Performance counter for measuring CPU cycles.
Definition PerformanceCounters.h:22
void stop()
Stops (pauses) the counters but do not set them to zeros.
Definition PerformanceCounters.hpp:34
void start()
Starts counters.
Definition PerformanceCounters.hpp:43
unsigned long long int getCPUCycles() const
Returns the number of CPU cycles (machine cycles) elapsed on this timer.
Definition PerformanceCounters.hpp:50
void reset()
Reset counters.
Definition PerformanceCounters.hpp:26
Output
Elapsed CPU cycles: 1805808944
CPU cycles after reset: 0

Member Function Documentation

◆ getCPUCycles()

unsigned long long int TNL::PerformanceCounters::getCPUCycles ( ) const
inline

Returns the number of CPU cycles (machine cycles) elapsed on this timer.

CPU cycles are counted by adding the number of CPU cycles between start and stop methods together.

◆ start()

void TNL::PerformanceCounters::start ( )
inline

Starts counters.

This method can be used also after using the stop method. The counters then continue the measuring.

◆ writeLog()

bool TNL::PerformanceCounters::writeLog ( Logger & logger,
int logLevel = 0 ) const
inline

Writes a record into the logger.

Parameters
loggerName of Logger object.
logLevelA non-negative integer recording the log record indent.
Example
#include <iostream>
#include <chrono>
#include <thread>
#include <TNL/Timer.h>
#include <TNL/Logger.h>
int
main()
{
const int milliseconds = 0.5e3;
TNL::Timer time;
time.start();
time.stop();
TNL::Logger logger( 50, std::cout );
time.writeLog( logger, 0 );
}
Creates calculations log in the form of a table.
Definition Logger.h:15
Class for real time, CPU time and CPU cycles measuring.
Definition Timer.h:25
Output
| Real time: 0.501562 |
| CPU time: 1.8e-05 |

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