Thread: Timing in C++?

  1. #1
    Registered User
    Join Date
    Mar 2005

    Timing in C++?

    I need some help with timing in c++. I have never used any ting that needed a timer. I don't evan know if their is a timer for C++. Please help.

  2. #2
    Super Moderator
    Join Date
    Sep 2001
    You'll find the standard functions in ctime (time.h). You can find other functions in other libraries, such as platform SDKs, etc... Do a board search too.

  3. #3
    Software Developer jverkoey's Avatar
    Join Date
    Feb 2003
    University of Waterloo
    Hmm...not sure exactly what you need to be done.

    There's a variety of time functions:

    Halts the program for n number of milliseconds

    ULONG ticks=GetTickCount();
    Quote Originally Posted by msdn
    The return value is the number of milliseconds that have elapsed since the system was started.

    DWORD time=timeGetTime();
    Quote Originally Posted by msdn
    Returns the system time, in milliseconds.
    Paired with:

    And a huge list of synchronization functions here:

  4. #4
    Registered User
    Join Date
    Apr 2003
    A timer in languages like javascript can be set to execute a function in a specifed number of seconds in the future. The code sets the timer and continues execution, and when the specified time elapses, the function executes.

  5. #5
    Registered User
    Join Date
    Sep 2004
    Ok, last explination was bad. In C++, I think any program you will need a timer in, will probably have some form of main loop. What I would suggest doing, is using either the libraries mentioned above, or something like SDL, which has timing functions that are fairly precise. Best idea is simply have a vector of "jobs" you cycle through at the begining or end of the loop, and check them against the current time to see if they are ready to go, by checking if their schedualed time is less then or equal too the current time.

    EDIT: ah, the libSDL site is working for me again, one sec and Ill check for any links on their timers.
    Ok, found it, check this link
    Last edited by Xipher; 03-09-2005 at 09:20 PM.
    If any part of my post is incorrect, please correct me.

    This post is not guarantied to be correct, and is not to be taken as a matter of fact, but of opinion or a guess, unless otherwise noted.

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, 11:43 PM
  4. Games - timing
    By Magos in forum Game Programming
    Replies: 7
    Last Post: 03-06-2004, 11:32 AM
  5. Timing in Windows
    By steinberg in forum Windows Programming
    Replies: 3
    Last Post: 07-14-2002, 12:43 AM