Thread: Timers

  1. #1
    MFC killed my cat! manutd's Avatar
    Join Date
    Sep 2006
    Location
    Boston, Massachusetts
    Posts
    870

    Timers

    Does anyone now of a good way to use timers in C++? I've tried using clock_t, but it keeps returning 0:
    Code:
    clock_t start = clock();
    //Do stuff....
    clock_t end = clock();
    double elapsed = static_cast<double>((end-start)/CLOCKS_PER_SEC);
    Last edited by manutd; 11-19-2006 at 03:42 PM.
    Silence is better than unmeaning words.
    - Pythagoras
    My blog

  2. #2
    Registered User Tonto's Avatar
    Join Date
    Jun 2005
    Location
    New York
    Posts
    1,465
    What is returning 0? Is it clock or your elapsed calculations? You should cast end-start to double and then perform the division. If you need more precision you should probably look into more platform specific timing mechanisms.

  3. #3
    MFC killed my cat! manutd's Avatar
    Join Date
    Sep 2006
    Location
    Boston, Massachusetts
    Posts
    870
    Elasped equals 0. Thanks for the tips, seperating the division worked.
    Silence is better than unmeaning words.
    - Pythagoras
    My blog

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Threads and Timers
    By scioner in forum C Programming
    Replies: 8
    Last Post: 03-22-2008, 07:56 AM
  2. Enumerating timers and hotkeys
    By maxorator in forum Windows Programming
    Replies: 3
    Last Post: 01-01-2007, 11:47 AM
  3. switch cases and timers
    By soranz in forum C++ Programming
    Replies: 5
    Last Post: 10-02-2005, 06:43 PM
  4. Timers, Timers, Timers!
    By Stan100 in forum Game Programming
    Replies: 9
    Last Post: 01-24-2003, 04:45 PM
  5. Timers
    By Mox in forum Windows Programming
    Replies: 2
    Last Post: 11-09-2001, 04:34 AM