Thread: time.h and miliseconds question

  1. #1
    Registered User Diamonds's Avatar
    Join Date
    Oct 2002
    Posts
    68

    time.h and miliseconds question

    using time.h seems to want to only give me seconds. Anyone know how to grab the time in miliseconds? Is there anything else that has more presision (sp?)?

  2. #2
    Registered User Diamonds's Avatar
    Join Date
    Oct 2002
    Posts
    68
    XP VC 6.0

    also it's a win32 api program
    if winblows has anthing like that.


    whatever happened to getting the raw value of the system clock? that sucker was in miliseconds, and a firggin huge number at that.

    Why OS btw?

  3. #3
    Registered User Diamonds's Avatar
    Join Date
    Oct 2002
    Posts
    68
    well, lemme tell you my problem, and hopefully you can suggest something.

    I want to only preform an operation after 30 miliseconds. I have the theory drawn out where I would get the time, then do a loop and compare that time with the current time. When the difference is > 30 miliseconds exit loop.

    Code:
    variable1
    variable2
    
    variable1 = getTimeInMiliseconds;
    variable2 = getTimeInMiliseconds;
    while (variabe1 - variable2 > 30) {
         //loop
         variable2 = getTimeInMiliseconds;
    }

  4. #4
    Code Monkey Davros's Avatar
    Join Date
    Jun 2002
    Posts
    812
    GetTickCount

    Certainly available in VC++.

  5. #5
    Shadow12345
    Guest
    if absolute precision is the name of the game GetTickCount may not be the best choice. Let me warn that more precision = moreoverhead, i.e it takes longer for the function to return a value

    look into
    timeGetTime
    and
    timeGetSystemTime (this is, i believe, the most accurate and precise)

    this gives a good explanation how to increase precision
    Last edited by Shadow12345; 12-16-2002 at 07:04 AM.

  6. #6
    Code Monkey Davros's Avatar
    Join Date
    Jun 2002
    Posts
    812
    >Let me warn that more precision = moreoverhead, i.e it takes longer for the function to return a value

    Although I'm going to argue about which method is best, but surely the longer it takes for the function to return, the less accurate it's going to be. I.e.

    Code:
    // I need the time NOW!
    DWORD now = timeGetTime(); // But this takes ages to return
    This reminds me of Heisenbergs Uncertainty Principle.

  7. #7
    Shadow12345
    Guest
    Although I'm going to argue about which method is best, but surely the longer it takes for the function to return, the less accurate it's going to be. I.e.



    code:--------------------------------------------------------------------------------
    // I need the time NOW!
    DWORD now = timeGetTime(); // But this takes ages to return
    --------------------------------------------------------------------------------
    No need to argue, if you say you know which ones is best please say so, I was just trying to say the basics and point to a valid resource, but im sure you know which is better Davros

    This reminds me of Heisenbergs Uncertainty Principle.
    This I'll start a fuss over, time isn't a particle getting moved by the energy transferred from photons of light when they collide

    Do you know how to use the timeBeginTime and timeEndTime and query performance functions to increase accuracy? I read over it somewhat but all the information automatically fell out of my head.

  8. #8
    Code Monkey Davros's Avatar
    Join Date
    Jun 2002
    Posts
    812
    >No need to argue, if you say you know which ones is best please say so

    I'm not going to argue because I don't know. I'm up for a discussion on this - if you want, but not an argument.

    I was just picking up on a point you made. If you say method X is much more accurate than method Y, but method X takes much longer to return, then method X can't be particularly accurate. (Not unless the time it takes to return is known precisely, which would be doubtful.)

    >This I'll start a fuss over, time isn't a particle getting moved by the energy transferred from photons of light when they collide

    Mmmm. I was simply making an analogy.

    Hands up all those who have a degree in Physics.
    OS: Windows XP
    Compilers: MinGW (Code::Blocks), BCB 5

    BigAngryDog.com

  9. #9
    Shadow12345
    Guest
    I was just picking up on a point you made. If you say method X is much more accurate than method Y, but method X takes much longer to return, then method X can't be particularly accurate. (Not unless the time it takes to return is known precisely, which would be doubtful.)
    Now that I think about it that way, that is a good point, however it is true that the more accurate time function takes longer, that is what it says on msdn, so it must be true!

    Maybe we should develop a rule then:
    If you need something that needs to calculate time many times (i.e frames per second per game) then use the slightly less accurate method (it hardly matters because in this case it only needs to determine if it is over 1000ms, so a small inaccuracy could only result in incorrectly report only a few frames.

    If however, you need something that doesn't need to be calculated many times per second, but needs absolute accuracy and precision, then go for the more accurate and precise methods that generate more overhead. I can't think of something that would require that much precision.

    Mmmm. I was simply making an analogy.

    Hands up all those who have a degree in Physics.
    sorry, I'm an ass

  10. #10
    Code Monkey Davros's Avatar
    Join Date
    Jun 2002
    Posts
    812
    >sorry, I'm an ass

    Not true. You almost had me digging through physics text books.
    OS: Windows XP
    Compilers: MinGW (Code::Blocks), BCB 5

    BigAngryDog.com

  11. #11
    Shadow12345
    Guest
    Not true. You almost had me digging through physics text books.
    maybe I should be a motivational speaker or something

    Hmm I wonder if we've helped Diamonds @ all lol

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. Replies: 5
    Last Post: 06-18-2009, 12:04 PM
  3. Best way to get miliseconds?
    By someprogr in forum C Programming
    Replies: 2
    Last Post: 01-16-2009, 08:35 PM
  4. time.h & Delay
    By gavra in forum C Programming
    Replies: 27
    Last Post: 07-29-2008, 08:53 AM