TStopwatch is a timer class in the ROOT package library that provides high-resolution timing functionality for measuring CPU and real time. It has two methods, CpuTime and RealTime, for measuring CPU and real time intervals respectively.
Example 1: Measuring CPU Time The following code example demonstrates the use of the CpuTime method to measure the elapsed CPU time between two points in the code.
In this example, the TStopwatch object is created and started using the Start method. The code block to be timed is then executed, and the elapsed CPU time is obtained using the CpuTime method. The result is printed to the console.
Example 2: Measuring Multiple CPU Time Intervals The following code example demonstrates the use of TStopwatch in measuring multiple CPU time intervals in a loop.
#include
int main() { TStopwatch timer; Double_t total_time = 0;
for (int i = 0; i < 10; ++i) { timer.Start();
// Code block to be timed // ...
Double_t cpu_time = timer.CpuTime(); std::cout << "Elapsed CPU time " << i << ": " << cpu_time << " s" << std::endl;
In this example, the TStopwatch object is created and its Start method is called at the beginning of each loop iteration. The code block to be timed is executed inside the loop, and the elapsed CPU time is obtained using the CpuTime method. The result is printed to the console, and the total CPU time is accumulated in the total_time variable. The Reset method is called at the end of each loop iteration to reset the timer for the next iteration.
Package Library: ROOT.
C++ (Cpp) TStopwatch::CpuTime - 30 examples found. These are the top rated real world C++ (Cpp) examples of TStopwatch::CpuTime extracted from open source projects. You can rate examples to help us improve the quality of examples.