Search code examples
c++qtqt4

Get time of execution piece of code


How do I get milliseconds time of execution of a piece of code in Qt/C++?


Solution

  • Use the QTime class. Start it with .start() (or .restart()) and then check the amount of milliseconds passed with .elapsed(). Naturally, the precision ultimately depends on the underlying OS, although with the major platforms you should have no trouble getting a real millisecond resolution.