Timing in C++?

This is a discussion on Timing in C++? within the C++ Programming forums, part of the General Programming Boards category; I need some help with timing in c++. I have never used any ting that needed a timer. I don't ...

  1. #1
    Registered User
    Join Date
    Mar 2005
    Posts
    13

    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
    Posts
    4,913
    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
    Location
    University of Waterloo
    Posts
    1,904
    Hmm...not sure exactly what you need to be done.

    There's a variety of time functions:

    -------------------------------------------------------
    Code:
    Sleep(n);
    http://msdn.microsoft.com/library/de...base/sleep.asp
    Halts the program for n number of milliseconds
    -------------------------------------------------------


    -------------------------------------------------------
    Code:
    ULONG ticks=GetTickCount();
    http://msdn.microsoft.com/library/de...ttickcount.asp
    Quote Originally Posted by msdn
    The return value is the number of milliseconds that have elapsed since the system was started.
    -------------------------------------------------------


    -------------------------------------------------------
    Code:
    DWORD time=timeGetTime();
    http://msdn.microsoft.com/library/de...imegettime.asp
    Quote Originally Posted by msdn
    Returns the system time, in milliseconds.
    Paired with:
    timeBeginPeriod
    and
    timeEndPeriod
    -------------------------------------------------------



    -------------------------------------------------------
    And a huge list of synchronization functions here:
    http://msdn.microsoft.com/library/de..._functions.asp

  4. #4
    Registered User
    Join Date
    Apr 2003
    Posts
    2,662
    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
    Posts
    197
    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 http://www.libsdl.org/intro/usingtimers.html
    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, 03:10 AM
  2. Performance Timing Function
    By rosicky2005 in forum C++ Programming
    Replies: 11
    Last Post: 05-31-2007, 04: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, 01:43 AM

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