Using standalone CPU profilers

To simulate excess CPU usage, we will add the following two lines to the main.cc 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 https://github.com/VerySleepy/verysleepy. Because, at the time of writing, the last released version, v0.90, cannot read the debug information of ...

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

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.