PDA

View Full Version : How to get CPU time?



babygal
16th September 2010, 10:49
I would like to display time elapsed.
So for that I need to get the CPU time.How to get the CPU time?

^NyAw^
16th September 2010, 11:18
Hi,

One thing is CPU time and another is total time. The CPU time is the time that your process have been into the CPU to execute the code. The total time includes the time that your process is out of the CPU because of Operating System schedeuler.
To get total time use the class QTime and take a look at int QTime::msecsTo(const QTime & t) const
If your would get the CPU time you need to use OS specific code.

babygal
17th September 2010, 12:04
Hi,

One thing is CPU time and another is total time. The CPU time is the time that your process have been into the CPU to execute the code. The total time includes the time that your process is out of the CPU because of Operating System schedeuler.
To get total time use the class QTime and take a look at int QTime::msecsTo(const QTime & t) const
If your would get the CPU time you need to use OS specific code.

How to decide which one to use?

^NyAw^
17th September 2010, 13:00
It depends on what you want.
The CPU time will get you the exact time that your process is on the CPU. The second includes the time that your process is not into the CPU.
Imagine that there is a process that is using 90% of CPU, so your program will get a time execution of 5 seconds, but really it have been on CPU only 1 second.
The real time that you or the user will see is the total time. The other time can be used when trying to improve the performance of your code.