Thread: timing issues

  1. #1
    jibblit
    Guest

    Question timing issues

    what is the simplelist way to put a delay in your program? that is, a pause of a known length of time before the code afterwards is executed?

    maybe an example:

    switch(variable){

    case 1:
    *some code*;
    ~~~Pause here for 1 second~~~;
    *some more code*;
    break;
    case 2:
    *some code*;
    ~~~Pause here for .5 seconds~~~;
    *some more code*;
    break;
    case 2:
    *some code*;
    ~~~Pause here for .25 seconds~~~;
    *some more code*;
    break;

    }


    etc...

    thanks for the help

  2. #2
    Registered User
    Join Date
    Mar 2002
    Posts
    88
    hmmm
    i think i dont sure
    i forgot

    the function delay();

    for exemple

    delay(1000);
    give you a second

    i dont remember how much is second

  3. #3
    Patent Pending GSLR's Avatar
    Join Date
    Sep 2001
    Posts
    134
    Hi

    A for loop will work but i found that it is dependent on the processor so slower machines take longer to run thriough the loop.












    And to all those opposed , MMmmm Well.

  4. #4
    jibblit
    Guest
    GSLR- yeah, it is processor dependent, and thats one of the main reason's i'm asking how to get around it. an empty for loop on my machine i found can run about 10000000 times to be close to a second, and i don't want to accidentally run that on a pentium2 in the lab- could be there a while.

    godlike- my compiler doesn't recognize the delay command, is it in a certain library? i've looked through a bunch of *.h files and can't find it.

    thanks guys

  5. #5
    The Artful Lurker Deckard's Avatar
    Join Date
    Jan 2002
    Posts
    633
    If your system supports it, try poll():
    Code:
    #include <poll.h>
    
    /* The third argument is the number of milliseconds to wait */
    
    poll( NULL, 0, 3500 ); /* wait 3.5 seconds */
    Jason Deckard

  6. #6
    Registered User
    Join Date
    Mar 2002
    Posts
    88
    hmmm

    i think it
    is <stdlib.h>

    i dont sure

    like i said
    i forgot everything

  7. #7
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    As far as I know, delay functions tend to be implementation dependent. You'd do better by maintaining portability and writing your own sleep function.
    Code:
    #include <time.h>
    
    void sleep ( long m )
    {
      clock_t limit, cl = clock ();
      limit = cl + m;
      while ( limit > cl )
        cl = clock ();
    }
    -Prelude
    My best code is written with the delete key.

Popular pages Recent additions subscribe to a feed

Similar Threads

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