Thread: Timing in C

  1. #1
    Registered User
    Join Date
    Jun 2003
    Posts
    2

    Question Timing in C

    Hello all, I was wondering if anybody could help me with timing in C.
    Im trying to make a solar system program, and putting aside all the OpenGL worries I have, Ive come stuck on trying to get a function to execute periodically without fail, ie. every second, minute or how ever many times per second/usec it will execute. Ive see functions such as sleep() and usleep(), but they delay things from happening... If anybody could help me id be very thankfull.
    Konrad.

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Two seconds and a search engine provide lots of ways to do it.

    ANSI Standard? Use something like time in a loop.

    Non-ANSI, there are plenty of ways. (IE: OS dependant. Using select, etc.)

    Isn't this in the FAQ? Why yes, yes it is!

    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    Man the FAQ has become quite a resource since I last visited the site regularly. Too bad most questions asked are in the FAQ. Maybe the problem with newbies is their reading comprehension.

  4. #4
    Registered User
    Join Date
    Jun 2003
    Posts
    2
    I can not see how that helps me. Ive seen what is in the FAQ before, it will give you the time between two stages by subtracting two different times.

    I dont want that, i want to be able to be able to make a function run exactly every second, or minute or so many times per second...

    I dont think waiting for the difference between two times gets to a certain value will be accurate and specfic enough...

  5. #5
    Been here, done that.
    Join Date
    May 2003
    Posts
    1,164
    Originally posted by Konrad
    I can not see how that helps me. Ive seen what is in the FAQ before, it will give you the time between two stages by subtracting two different times.

    I dont want that, i want to be able to be able to make a function run exactly every second, or minute or so many times per second...

    I dont think waiting for the difference between two times gets to a certain value will be accurate and specfic enough...
    Look into threads, running two or more portions of a program at the same time.

    This gets complicated, but it will do what you want.
    Definition: Politics -- Latin, from
    poly meaning many and
    tics meaning blood sucking parasites
    -- Tom Smothers

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