xref: /csrg-svn/usr.bin/f77/libU77/dtime_.c (revision 23008)
12406Sdlw /*
2*23008Skre  * Copyright (c) 1980 Regents of the University of California.
3*23008Skre  * All rights reserved.  The Berkeley software License Agreement
4*23008Skre  * specifies the terms and conditions for redistribution.
52406Sdlw  *
6*23008Skre  *	@(#)dtime_.c	5.1	06/07/85
7*23008Skre  */
8*23008Skre 
9*23008Skre /*
102406Sdlw  * Returns the delta time since the last call to dtime.
112406Sdlw  *
122406Sdlw  * calling sequence:
132406Sdlw  * 	real time(2)
142406Sdlw  * 	call dtime(time)
152406Sdlw  * where:
162406Sdlw  * 	the 2 element array time will receive the user and system
172406Sdlw  * 	elapsed time since the last call to dtime, or since the start
182406Sdlw  * 	of execution.
192406Sdlw  *
202406Sdlw  * This routine can be called as function, and returns the sum of
212406Sdlw  * user and system times. The time_array argument must always be given.
222406Sdlw  *
232406Sdlw  * The resolution for all timing is 1/60 second.
242406Sdlw  */
252406Sdlw 
262406Sdlw #include <sys/types.h>
272406Sdlw #include <sys/times.h>
282406Sdlw 
292406Sdlw struct tb { float usrtime; float systime; };
302406Sdlw 
312406Sdlw time_t dutime=0, dstime=0;
322406Sdlw 
332406Sdlw float
342406Sdlw dtime_(dt) struct tb *dt;
352406Sdlw {	struct tms clock;
362406Sdlw 
372406Sdlw 	times(&clock);
382406Sdlw 	dt->usrtime = (float)(clock.tms_utime - dutime) / 60.0;
392406Sdlw 	dt->systime = (float)(clock.tms_stime - dstime) / 60.0;
402406Sdlw 	dutime = clock.tms_utime;
412406Sdlw 	dstime = clock.tms_stime;
422406Sdlw 	return(dt->usrtime + dt->systime);
432406Sdlw }
44