Thread: How to timing?

  1. #1
    Unregistered
    Guest

    Question How to timing?

    Hi everybody!

    I'm using Turbo C 2.0.
    I want to use timers in my program. How to do it? Are there any functions for it, or maybe asm needed?My C knowledge is rather big, but I don't know anything about timing !

    Thanks in advance!

  2. #2
    Registered User
    Join Date
    Sep 2001
    Posts
    5

    Time.h

    Check the Help on time.h If there is such a thing in TC2.

    I use TC3, but i need something more accurate than these timing functions.

  3. #3
    Registered User
    Join Date
    Sep 2001
    Posts
    3

    Where is it?

    Hi(I'm registered now)!

    I don't see any time.h!Would you explain it there?

  4. #4
    Registered User
    Join Date
    Sep 2001
    Posts
    5
    Well, you need to #include time.h to have the function clock() which returns the numer of ticks your CPU made since your app is running. Dividing that by constant CLK_TCK (also in time.h) results in seconds, dividing that by 1000 results in milliseconds (but not accurate, i checked the restults, only accurate to 5/100 sec )

    Someone else using TC2 here that has an alternative?

  5. #5
    Registered User
    Join Date
    Sep 2001
    Posts
    3

    Maybe it will help you!

    I hope what I attached'll help you!I'm not sure that it is absolutely precise, give a test for it !

  6. #6
    Registered User
    Join Date
    Sep 2001
    Posts
    4,912
    The two files which people have referenced are very helpful, but if you're not looking for accuracy, and you're just loking for an quick pause, you can just have a really long (repeated about 1,000,000 times, do nothing loop (adjust the number, but be aware, slower computer will take longer, faster ones will take less time. Consider your audience.

  7. #7
    Registered User
    Join Date
    Oct 2001
    Posts
    11

    maybe it's your solution

    use this method :

    typedef unsigned short word;

    word start;

    float t1;

    word *my_clock=(word *)0x0000046C;
    /* this points to the 18.2hz system clock. */


    srand(*my_clock); /* seed the number generator. */

    start=*my_clock; /* record the starting time. */

    t1=(*my_clock-start)/18.2; /* calculate how long it took. */


    /*I took those codes from http://www.brackeen.com/home/vga/sou...1/pixel.c.html */

  8. #8
    Registered User
    Join Date
    Oct 2001
    Posts
    11
    sorry i forgot to include stdlib.h

  9. #9
    Former Member
    Join Date
    Oct 2001
    Posts
    955
    if you want a quick pause, you could also use the delay() function, it's in dos.h, I think, it's like this

    delay(100); //For a 100 ms pause

    delay(1); //For a 1 ms pause

    delay(100000) //For a 100 s pause


    if you want it to pause until it receives a key, use getch();



    Good Luck

    Oskilian

  10. #10
    Registered User
    Join Date
    Oct 2001
    Posts
    10
    If you are running programs in msdos prompt you can use Win API function called GetTickCount() (or view my post in general c forum).
    #cd pub
    #more beer

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