Using standalone CPU profilers

To simulate excess CPU usage, we will add the following two lines to the file of the preceding example project before the return statement:

// waste timewasteCpuCycles();return app.exec();

The wasteCpuCycles() function will waste time with floating-point divisions in the following manner:

void wasteCpuCycles(){  size_t count = 10000000;  double result = 0;  for(size_t i = 0; i < count; ++i)  {    result += i / 2.33;  }  qDebug() << QString("Wasted %1 divisions, result=%2")                .arg(count).arg(result);}

First, we will try out the Very Sleepy profiler. To install it, go to Because, at the time of writing, the last released version, v0.90, cannot read the debug information ...

Get Hands-On High Performance Programming with Qt 5 now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.