Timing

This is a discussion on Timing within the C++ Programming forums, part of the General Programming Boards category; Does anybody know of a good way for getting system time? i've tried timeGetTime but maybe I didn't do it ...

  1. #1
    Registered User jimboob's Avatar
    Join Date
    Jun 2004
    Posts
    40

    Timing

    Does anybody know of a good way for getting system time?
    i've tried timeGetTime but maybe I didn't do it right. I put the below code into the program but the numbers it outputted came out bizaar.


    ///////////////////////////////////////////////////////

    float FrameInterval;

    void CalculateSpeed()
    {

    static float lastTime = 0.0f;

    static float frameTime = 0.0f;

    float currentTime = timeGetTime();

    FrameInterval = currentTime - frameTime;
    frameTime = currentTime;
    }

    ////////////////////////////////////////////////////////////

    This code is actually for an OpenGL program i'm 'trying' to make which is based on Time Based Movement. I read some tutorials and the 'timeGetTime' function was the one they recommended. I posted this in this Board instead of the "Game Programming Board" because I figured it had more to do with the whole of C++.
    TIA

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,439
    > I put the below code into the program but the numbers it outputted came out bizaar.
    So show how you output the numbers, and what sort of output you get
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User jimboob's Avatar
    Join Date
    Jun 2004
    Posts
    40
    Whoops... Sorry about above code compared to this one... I used the old code on the above example...
    Heres the whole Program
    ///////////////////////////////////////////////////////

    #include <windows.h>
    #include <iostream.h>
    #include <mmsystem.h>

    float FrameInterval = 0.0f;

    void CalculateSpeed()
    {
    static float frameTime = 0.0f; // This stores the last frame's time

    float currentTime = timeGetTime() * 0.001f;

    FrameInterval = currentTime - frameTime;
    frameTime = currentTime;
    }



    int main()
    {
    for (int index = 0; index < 100000000000; index++)
    {
    CalculateSpeed();
    cout << FrameInterval << endl;
    }
    return 0;
    }

    /////////////////////////////////////////////////////

    I get a group of numbers.... Something like
    0.0076599 and repeats a couple of times
    0.0076598 and repeats a couple of times
    0.0076597 and repeats a couple of times
    And it keeps counting down.

    Is there a possibility my computer is too fast for timeGetTime?
    I have a athlon2500xp @ 3200xp

    Thanks

  4. #4
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,439
    Try outputting timeGetTime() without all the float arithmetic

    I'd expect some variation from one call to the next (calculating time differences), so it should wander around some mean value.
    Are you sure it counts down to 0?

    Also, if you want to preserve all the accuracy returned by timeGetTime(), you need a double, not a float.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Timing basic operations in C++
    By StevenGarcia in forum C++ Programming
    Replies: 9
    Last Post: 09-18-2007, 02:10 AM
  2. Performance Timing Function
    By rosicky2005 in forum C++ Programming
    Replies: 11
    Last Post: 05-31-2007, 03:09 PM
  3. My Timing System
    By jmd15 in forum Windows Programming
    Replies: 4
    Last Post: 01-01-2006, 10:43 PM
  4. Games - timing
    By Magos in forum Game Programming
    Replies: 7
    Last Post: 03-06-2004, 10:32 AM
  5. Timing in Windows
    By steinberg in forum Windows Programming
    Replies: 3
    Last Post: 07-14-2002, 12:43 AM

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