#includeint main() { TStopwatch timer; timer.Start(); // code to be timed for (int i = 0; i < 10000000; i++) { // do something } timer.Stop(); cout << "Time taken: " << timer.RealTime() << " seconds" << endl; return 0; }
#includeIn this example, we create a function called `testFunction()` that does some operation 10 million times. We then create a TStopwatch object called `timer` and start it. We call `testFunction()` and after it returns, we stop the timer and print the elapsed time using the `RealTime()` method. Overall, TStopwatch RealTime is a useful library in C++ for measuring the elapsed time of a program or code execution. It is part of the ROOT package library and can be used for data analysis and visualization in high energy physics.double testFunction() { // code to be timed for (int i = 0; i < 10000000; i++) { // do something } return 0.0; } int main() { TStopwatch timer; timer.Start(); // function call to be timed testFunction(); timer.Stop(); cout << "Time taken: " << timer.RealTime() << " seconds" << endl; return 0; }