1

I just made some benchmarks for this super question/answer Why is my program slow when looping over exactly 8192 elements?

I want to do benchmark on one core so the program is single threaded. But it doesn't reach 100% usage of one core, it uses 60% at most. So my tests are not acurate.

I'm using Qt Creator, compiling using MinGW release mode.

Are there any parameters to setup for better performance ? Is it normal that I can't leverage CPU power ? Is it Qt related ? Is there some interruptions or something preventing code to run at 100%...

Here is the main loop

//  horizontal sums for first two lines
for(i=1;i<SIZE*2;i++){ 
    hsumPointer[i]=imgPointer[i-1]+imgPointer[i]+imgPointer[i+1];
}
// rest of the computation
for(;i<totalSize;i++){ 
    // compute horizontal sum for next line
    hsumPointer[i]=imgPointer[i-1]+imgPointer[i]+imgPointer[i+1];
    // final result
    resPointer[i-SIZE]=(hsumPointer[i-SIZE-SIZE]+hsumPointer[i-SIZE]+hsumPointer[i])/9; 
}

This is run 10 times on an array of SIZE*SIZE float with SIZE=8193, the array is on the heap.

Community
  • 1
  • 1
bokan
  • 3,601
  • 2
  • 23
  • 38
  • 4
    I don't see anything in the linked question that can be affected by Qt. – Šimon Tóth Sep 06 '12 at 10:45
  • 3
    How are we supposed to answer your question without seeing your source code? – bjoernz Sep 06 '12 at 10:46
  • IMHO, room for improvement depends not only on library/ environment you use, but also on your program design, I mean: if it is possible to parallel processes executed by program if it is real when to improve it`s performance you can refer to multi threading techincs as far as I know in Qt this can be done by means of signals and slots. if organizing program in such way impossible due to it`s design nothing can`t improve it`s performance ) – spin_eight Sep 06 '12 at 10:50
  • @bjoernz Like Let_Me_Be has done, and the code is on the link provided. – bokan Sep 06 '12 at 11:34
  • 3
    There isn't quite enough info here yet. There could be several reasons why Task Manager isn't showing 100% CPU usage on 1 core: (1) you have a multiprocessor system and the load is getting spread across multiple CPUs (most OSes will do this unless you specify a more restrictive CPU affinity); (2) the run isn't long enough to span a complete Task Manager sampling period; (3) you have run out of RAM and are swapping heavily, meaning lots of time is spent waiting for disk I/O when reading/writing memory. Also Let_Me_Be is right -- nothing here is QT's fault. – j_random_hacker Sep 06 '12 at 11:46
  • 1
    How long does the entire program run, in seconds? A program is either running or waiting, at any instant of time. Either 100% or 0%, nothing in between. %CPU is just an average over some window of time, like maybe 500ms. – Mike Dunlavey Sep 06 '12 at 11:48
  • @j_random_hacker Can you please make it an answer ? It's the good one. – bokan Sep 06 '12 at 11:53
  • Thanks :) I've added a slightly fleshed-out answer. – j_random_hacker Sep 06 '12 at 12:01

1 Answers1

1

There could be several reasons why Task Manager isn't showing 100% CPU usage on 1 core:

  1. You have a multiprocessor system and the load is getting spread across multiple CPUs (most OSes will do this unless you specify a more restrictive CPU affinity);
  2. The run isn't long enough to span a complete Task Manager sampling period;
  3. You have run out of RAM and are swapping heavily, meaning lots of time is spent waiting for disk I/O when reading/writing memory.

Or it could be a combination of all three.

Also Let_Me_Be's comment on your question is right -- nothing here is QT's fault, since no QT functions are being called (assuming that the objects being read and written to are just simple numeric data types, not fancy C++ objects with overloaded operator=() or something). The only activities taking place in this region of the code are purely CPU-based (well, the CPU will spend some time waiting for data to be sent to/from RAM, but that is counted as CPU-in-use time), so you would expect to see 100% CPU utilisation except under the conditions given above.

j_random_hacker
  • 50,331
  • 10
  • 105
  • 169