View Full Version : How to timing?

09-28-2001, 01:54 PM
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!

09-28-2001, 02:06 PM
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.

09-28-2001, 02:31 PM
Hi(I'm registered now)!

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

09-28-2001, 02:49 PM
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?

09-28-2001, 03:32 PM
I hope what I attached'll help you!I'm not sure that it is absolutely precise, give a test for it ;) !

10-05-2001, 08:04 PM
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.

10-05-2001, 10:03 PM
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/source/bc31/pixel.c.html */

10-05-2001, 10:13 PM
sorry i forgot to include stdlib.h

10-11-2001, 03:11 PM
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


10-21-2001, 06:47 AM
If you are running programs in msdos prompt you can use Win API function called GetTickCount() (or view my post in general c forum).