Mail Archives: djgpp/1997/04/24/09:06:32
I am trying to follow the many recommendations to use uclock() but am
getting inconsistent results. I am working in a DOS window of WinNT3.51 on
a 200MHz Pentium Pro. Below is a test program to see just how long a call
to uclock() takes. I call uclock() 100 times, store the values in an array,
and print the difference array. The output is in uclock ticks, about 840 ns
each. The first value printed is not 0, although the info page says the
first call to uclock() resets it. Why should each call take more than 10
ms? Also, every third or fourth value is negative - why? What am I doing
wrong?
Roger Noss
#include <time.h>
#include <stdio.h>
int main(void) /* testing uclock() */
{
uclock_t t0, dt[100];
short i;
printf( "%d\n", (int) t0 ); /* first call resets clock to 0 */
for (i=0; i<100; i++) dt[i] = uclock();
for (i=1; i < 100; i++) {
printf( "%d ", (int) ( dt[i] - dt[i-1] ) );
if (!(i%10)) printf( "\n" );
}
}
Here is the output:
313012
16128 15872 -49408 15617 15872 15872 -49920 15873 15872 15616
-49408 15617 15872 15616 15872 -49663 15616 -1791 16128 15360
-49663 15616 15872 15616 -49664 15617 15616 15872 -49920 15873
15872 15360 -49664 15617 15872 15616 15616 -49663 15616 15872
15616 -49663 15872 15616 15872 -50175 15872 15616 15872 -45823
15872 15360 15872 -49920 15873 15872 15616 -49920 15617 15872
15616 -49664 15873 15360 15872 -49920 15873 15872 15616 15616
-49919 15872 15616 15872 -49663 15360 15872 15616 -49664 15873
15360 15872 -49920 19201 15872 15616 -49664 15617 15872 15872
-49920 15873 15616 15872 -49664 15617 15872 15616 15872
- Raw text -