Thread: Best way to get miliseconds?

  1. #1
    Registered User
    Join Date
    Dec 2007

    Best way to get miliseconds?

    Whats the best way to get the current time in milliseconds for C? Time.h seems to have only stuff for hours:minutes:seconds.

    I ask because I am trying to emulate a CPU which is significantly slower than the host CPU. I have to calculate cycles in MHz and slow it down to its correct speed. I figure I can get it as accurate to a millisecond, because seconds obviously wouldn't be too accurate at all. Thanks.

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Farncombe, Surrey, England
    The C function clock() is normally "more accurate".

    Beyond that, you will have to use OS-specific functions, such as gettimeofday() in linux or GetSystemTime() in Windows.

    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    Registered User
    Join Date
    Sep 2006
    This is the best info and example on it, that I've seen, for WindowsXP:

    This uses the Windows high performance timer, and is far better than what can be done, without it.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. get ping time in miliseconds from the socket?
    By Anddos in forum Networking/Device Communication
    Replies: 1
    Last Post: 06-26-2009, 10:27 AM
  2. time.h and miliseconds question
    By Diamonds in forum C++ Programming
    Replies: 10
    Last Post: 12-16-2002, 08:41 AM