delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/02/11/09:39:58

Date: Tue, 11 Feb 1997 09:22:36 -0500 (EST)
From: Michael Phelps <morphine AT hops DOT cs DOT jhu DOT edu>
To: Jan Hubicka <hubicka AT atrey DOT karlin DOT mff DOT cuni DOT cz>
cc: djgpp AT delorie DOT com
Subject: Re: exact timming
In-Reply-To: <199702111201.NAA17664@atrey.karlin.mff.cuni.cz>
Message-ID: <Pine.GSO.3.95.970211091924.29877A-100000@hops.cs.jhu.edu>
MIME-Version: 1.0

On Tue, 11 Feb 1997, Jan Hubicka wrote:

> I have small problem:
> XaoS needs to quite exactly time one part of program. (Uses it to calculate
> framerate: time*5 so for framerate 30 I need to know time in precisity 1/150sec.
> ) higher precisity is better.
> Gettimeofday(I using in unix) is not exact enought (1/18.2sec...4 or inf frames
> per second) 
> 
> What is the best way to time this? Only I know about is to attach timer, set
> it to higher rate and make some my own counter. Can some send me code for this?
> Since I am lazy to study all irq attaching stuff under dpmi. Last time I did
> this is about 5 years ago in assembly.
> 
> Honza
> 

Why reinvent the wheel?  Try the uclock() library function, which has a
resolution better than 1 microsecond:

#include <stdio.h>
#include <time.h>

int	main()
{
	uclock_t	start, end;

	start = uclock();
	/* put your code here */
	end = uclock();

	printf("Total time:  %fs\n", (double)(end - start) /
		UCLOCKS_PER_SEC);

	return 0;
}



						---Michael Phelps
						   morphine AT cs DOT jhu DOT edu


                               CH3
                               |
                               N
                             / |
                     ______/   |
                    /      \   CH2
             _____/         \__|__      
           //     \\        /  |  \\     
         //        \\______/___CH2 \\  
          \        /       \       /
           \______/         \_____/
          / ------ \       /      \
        OH           \   /         OH
                       O
 
                   Morphine



- Raw text -


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