Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

C++ time

  1. Jul 25, 2008 #1
    I have been using the time.h header and the difftime function is good if you want to know the difference between two events measured in seconds but how do you get the difference between two events that occur milliseconds apart?
  2. jcsd
  3. Jul 25, 2008 #2


    User Avatar
    Science Advisor
    Homework Helper

    It depends on your operating system.
    On windows QueryPerformanceCounter() will tell you the number of ticks since the last call, PerformanceCounterFrequency() tells you the frequency of the ticks ( it's about 10Mhz IIRC). Also take a look at 'multimedia timers'.
  4. Jul 25, 2008 #3
    I am using Linux.
  5. Jul 25, 2008 #4


    User Avatar
    Science Advisor
    Homework Helper

    gettimeofday() contains microseconds since start of day,
    I don't know what frequency it is updated at.
    But if you google for QueryPerformanceCounter() alternatives under linux you should find something.
  6. Jul 28, 2008 #5
    Yes, gettimeofday is a good alternative. Function details here: http://www.linuxmanpages.com/man2/gettimeofday.2.php
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?

Similar Discussions: C++ time
  1. Time Delay in C++. (Replies: 18)

  2. C++ Time Delay (Replies: 4)

  3. Timing mechanism in C (Replies: 19)