QElapsedTimer timer; timer.start(); myFunction(); // function to be timed qDebug() << "Elapsed time:" << timer.nsecsElapsed() << "ns";
QElapsedTimer timer; timer.start(); for(int i=0; i<1000000; i++) { /* do something */ } qDebug() << "Elapsed time:" << timer.nsecsElapsed() << "ns";This code starts the timer, loops one million times, and then prints the elapsed time in nanoseconds. These examples demonstrate the capabilities of the QElapsedTimer class for measuring precise elapsed time in C++ programs. It is part of the Qt Core library.