xref: /csrg-svn/usr.bin/f77/libU77/dtime_.c (revision 2406)
1*2406Sdlw /*
2*2406Sdlw char id_dtime[] = "@(#)dtime_.c	1.1";
3*2406Sdlw  *
4*2406Sdlw  * Returns the delta time since the last call to dtime.
5*2406Sdlw  *
6*2406Sdlw  * calling sequence:
7*2406Sdlw  * 	real time(2)
8*2406Sdlw  * 	call dtime(time)
9*2406Sdlw  * where:
10*2406Sdlw  * 	the 2 element array time will receive the user and system
11*2406Sdlw  * 	elapsed time since the last call to dtime, or since the start
12*2406Sdlw  * 	of execution.
13*2406Sdlw  *
14*2406Sdlw  * This routine can be called as function, and returns the sum of
15*2406Sdlw  * user and system times. The time_array argument must always be given.
16*2406Sdlw  *
17*2406Sdlw  * The resolution for all timing is 1/60 second.
18*2406Sdlw  */
19*2406Sdlw 
20*2406Sdlw #include <sys/types.h>
21*2406Sdlw #include <sys/times.h>
22*2406Sdlw 
23*2406Sdlw struct tb { float usrtime; float systime; };
24*2406Sdlw 
25*2406Sdlw time_t dutime=0, dstime=0;
26*2406Sdlw 
27*2406Sdlw float
28*2406Sdlw dtime_(dt) struct tb *dt;
29*2406Sdlw {	struct tms clock;
30*2406Sdlw 
31*2406Sdlw 	times(&clock);
32*2406Sdlw 	dt->usrtime = (float)(clock.tms_utime - dutime) / 60.0;
33*2406Sdlw 	dt->systime = (float)(clock.tms_stime - dstime) / 60.0;
34*2406Sdlw 	dutime = clock.tms_utime;
35*2406Sdlw 	dstime = clock.tms_stime;
36*2406Sdlw 	return(dt->usrtime + dt->systime);
37*2406Sdlw }
38