1 /**************************************************************************
3 * Copyright (C) 1995 Silicon Graphics, Inc.
5 * These coded instructions, statements, and computer programs were
6 * developed by SGI for public use. If any changes are made to this code
7 * please try to get the changes back to the author. Feel free to make
8 * modifications and changes to the code and release it.
10 **************************************************************************/
12 /* FUZZ: disable check_for_math_include */
16 #include <sys/param.h>
28 timevaldouble(struct timeval
*tin
)
30 return ((double)tin
->tv_sec
+ ((double)tin
->tv_usec
/ USECINSEC
));
35 doubletimeval(const double tin
, struct timeval
*tout
)
37 tout
->tv_sec
= (long)floor(tin
);
38 tout
->tv_usec
= (long)((tin
- tout
->tv_sec
) * USECINSEC
);
43 addtime(struct timeval
*OrigTime
, struct timeval
*NewTime
)
45 OrigTime
->tv_usec
+= NewTime
->tv_usec
;
46 if(OrigTime
->tv_usec
>= USECINSEC
)
52 OrigTime
->tv_usec
-= USECINSEC
;
54 OrigTime
->tv_sec
+= NewTime
->tv_sec
;
59 compdifftime(struct timeval
*EndTime
, struct timeval
*StartTime
, struct timeval
*DiffTime
)
61 struct timeval endtime
= *EndTime
;
63 if((endtime
.tv_usec
- StartTime
->tv_usec
) < 0)
68 endtime
.tv_usec
+= USECINSEC
;
71 DiffTime
->tv_usec
= endtime
.tv_usec
- StartTime
->tv_usec
;
72 DiffTime
->tv_sec
= endtime
.tv_sec
- StartTime
->tv_sec
;
77 mintime(struct timeval
*CurrMinTime
, struct timeval
*CheckMinTime
)
79 if(CheckMinTime
->tv_sec
< CurrMinTime
->tv_sec
)
81 *CurrMinTime
= *CheckMinTime
;
84 if(CheckMinTime
->tv_sec
== CurrMinTime
->tv_sec
)
86 if(CheckMinTime
->tv_usec
< CurrMinTime
->tv_usec
)
88 *CurrMinTime
= *CheckMinTime
;
96 maxtime(struct timeval
*CurrMaxTime
, struct timeval
*CheckMaxTime
)
98 if(CheckMaxTime
->tv_sec
> CurrMaxTime
->tv_sec
)
100 *CurrMaxTime
= *CheckMaxTime
;
103 if(CheckMaxTime
->tv_sec
== CurrMaxTime
->tv_sec
)
105 if(CheckMaxTime
->tv_usec
> CurrMaxTime
->tv_usec
)
107 *CurrMaxTime
= *CheckMaxTime
;
114 avgtime(struct timeval
*TotalTime
, int NumTimes
, struct timeval
*AvgTime
)
118 meantime
= mean(timevaldouble(TotalTime
), NumTimes
);
120 doubletimeval(meantime
, AvgTime
);
125 sqtime(struct timeval
*Time
, struct timeval
*SqTime
)
129 sec
= timevaldouble(Time
);
130 sec
*= sec
; /* square */
132 doubletimeval(sec
, SqTime
);
137 variancetime(struct timeval
*SumTime
, double SumSquareTime
, int NumTimes
, struct timeval
*VarianceTime
)
141 result
= variance(timevaldouble(SumTime
), SumSquareTime
, NumTimes
);
143 doubletimeval(result
, VarianceTime
);
148 stddevtime(struct timeval
*SumTime
, double SumSquareTime
,
149 int NumTimes
, struct timeval
*StdDevTime
)
153 result
= stddev(timevaldouble(SumTime
), SumSquareTime
, NumTimes
);
155 doubletimeval(result
, StdDevTime
);
159 thruputpersec(const double n
, struct timeval
*t
)
163 tv
= timevaldouble(t
);
165 return n
/ timevaldouble(t
);