Results 1 to 4 of 4

Thread: How to get CPU time?

  1. #1
    Join Date
    Apr 2010
    Location
    Singapore
    Posts
    156
    Thanks
    47
    Qt products
    Qt4
    Platforms
    Windows

    Question How to get CPU time?

    I would like to display time elapsed.
    So for that I need to get the CPU time.How to get the CPU time?

  2. #2
    Join Date
    Jan 2006
    Location
    Sta. Eugènia de Berga (Vic - Barcelona - Spain)
    Posts
    869
    Thanks
    70
    Thanked 59 Times in 57 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How to get CPU time?

    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) constIf your would get the CPU time you need to use OS specific code.
    Òscar Llarch i Galán

  3. #3
    Join Date
    Apr 2010
    Location
    Singapore
    Posts
    156
    Thanks
    47
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to get CPU time?

    Quote Originally Posted by ^NyAw^ View Post
    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) constIf your would get the CPU time you need to use OS specific code.
    How to decide which one to use?

  4. #4
    Join Date
    Jan 2006
    Location
    Sta. Eugènia de Berga (Vic - Barcelona - Spain)
    Posts
    869
    Thanks
    70
    Thanked 59 Times in 57 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How to get CPU time?

    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.
    Òscar Llarch i Galán

Similar Threads

  1. Replies: 6
    Last Post: 18th August 2010, 12:52
  2. Replies: 1
    Last Post: 25th June 2010, 18:31
  3. check the time of last time keyboard is pressed
    By Aki Tomar in forum General Programming
    Replies: 2
    Last Post: 5th February 2008, 09:10
  4. Qt 4.2.1 Run Time Error
    By Rayven in forum Qt Programming
    Replies: 1
    Last Post: 31st October 2006, 16:13
  5. <time.h>
    By mickey in forum General Programming
    Replies: 7
    Last Post: 3rd March 2006, 13:02

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.