Template Numerical Library: TNL::PerformanceCounters Struct Reference

Template Numerical Library version\ main:be7e16d88

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 reset 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();
  std::this_thread::sleep_for( std::chrono::milliseconds( milliseconds ) );
  performanceCounters.stop();
  std::cout << "Elapsed CPU cycles: " << performanceCounters.getCPUCycles() << '\n';
  performanceCounters.reset();
  std::cout << "CPU cycles after reset: " << performanceCounters.getCPUCycles() << '\n';
  }
  std::cout
  std::chrono::milliseconds
  std::this_thread::sleep_for
  T sleep_for(T... args)
  TNL::PerformanceCounters
  Performance counter for measuring CPU cycles.
  Definition PerformanceCounters.h:22
  TNL::PerformanceCounters::stop
  void stop()
  Stops (pauses) the counters but do not set them to zeros.
  TNL::PerformanceCounters::start
  void start()
  Starts counters.
  TNL::PerformanceCounters::getCPUCycles
  unsigned long long int getCPUCycles() const
  Returns the number of CPU cycles (machine cycles) elapsed on this timer.
  TNL::PerformanceCounters::reset
  void reset()
  Reset counters.

Output
  Elapsed CPU cycles: 1700296786
  CPU cycles after reset: 0

## Member Function Documentation

## ◆ getCPUCycles()

unsigned long long int TNL::PerformanceCounters::getCPUCycles | ( |  | ) | const
| nodiscard

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 | ( |  | ) |

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

Writes a record into the logger.

Parameters

  logger | Name of Logger object.
  logLevel | A 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();
  std::this_thread::sleep_for( std::chrono::milliseconds( milliseconds ) );
  time.stop();
  TNL::Logger logger( 50, std::cout );
  time.writeLog( logger, 0 );
  }
  TNL::Logger
  Creates calculations log in the form of a table.
  Definition Logger.h:15
  TNL::Timer
  Class for real time, CPU time and CPU cycles measuring.
  Definition Timer.h:25

Output
  | Real time: 0.500083 |
  | CPU time: 0 |

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

- src/TNL/PerformanceCounters.h