Best way to get miliseconds?

This is a discussion on Best way to get miliseconds? within the C Programming forums, part of the General Programming Boards category; Whats the best way to get the current time in milliseconds for C? Time.h seems to have only stuff for ...

  1. #1
    Registered User
    Join Date
    Dec 2007
    Posts
    51

    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
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    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.

    --
    Mats
    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
    Posts
    8,868
    This is the best info and example on it, that I've seen, for WindowsXP:

    http://tttarabians.com/sudoku/Timing_Snippet.txt

    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, 07:41 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21