www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/04/24/09:06:32

Message-Id: <1.5.4.32.19970424124818.002d7ec8@ubeclu.unibe.ch>
Mime-Version: 1.0
Date: Thu, 24 Apr 1997 14:48:18 +0200
To: djgpp AT delorie DOT com
From: Roger Noss <noss AT pupk DOT unibe DOT ch>
Subject: testing uclock()

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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019