Merge pull request #2309 from mitza-oci/warnings
[ACE_TAO.git] / ACE / apps / JAWS / clients / WebSTONE / src / timefunc.c
blob0ce7082ed8b0afb17cb4da90cb7999297e5e8c12
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 */
13 #ifndef WIN32
14 #include <netdb.h>
15 #include <sys/time.h>
16 #include <sys/param.h>
17 #else
18 #include <windows.h>
19 #include <winsock.h>
20 #include <time.h>
21 #endif /* WIN32 */
22 #include <math.h>
23 #include <stdio.h>
24 #include "sysdep.h"
25 #include "bench.h"
27 double
28 timevaldouble(struct timeval *tin)
30 return ((double)tin->tv_sec + ((double)tin->tv_usec / USECINSEC));
34 void
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 );
42 void
43 addtime(struct timeval *OrigTime, struct timeval *NewTime)
45 OrigTime->tv_usec += NewTime->tv_usec;
46 if(OrigTime->tv_usec >= USECINSEC)
49 * NEED TO CARRY 1.
51 OrigTime->tv_sec++;
52 OrigTime->tv_usec -= USECINSEC;
54 OrigTime->tv_sec += NewTime->tv_sec;
58 void
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)
66 * NEED TO BORROW.
68 endtime.tv_usec += USECINSEC;
69 endtime.tv_sec--;
71 DiffTime->tv_usec = endtime.tv_usec - StartTime->tv_usec;
72 DiffTime->tv_sec = endtime.tv_sec - StartTime->tv_sec;
76 void
77 mintime(struct timeval *CurrMinTime, struct timeval *CheckMinTime)
79 if(CheckMinTime->tv_sec < CurrMinTime->tv_sec)
81 *CurrMinTime = *CheckMinTime;
82 return;
84 if(CheckMinTime->tv_sec == CurrMinTime->tv_sec)
86 if(CheckMinTime->tv_usec < CurrMinTime->tv_usec)
88 *CurrMinTime = *CheckMinTime;
89 return;
95 void
96 maxtime(struct timeval *CurrMaxTime, struct timeval *CheckMaxTime)
98 if(CheckMaxTime->tv_sec > CurrMaxTime->tv_sec)
100 *CurrMaxTime = *CheckMaxTime;
101 return;
103 if(CheckMaxTime->tv_sec == CurrMaxTime->tv_sec)
105 if(CheckMaxTime->tv_usec > CurrMaxTime->tv_usec)
107 *CurrMaxTime = *CheckMaxTime;
108 return;
113 void
114 avgtime(struct timeval *TotalTime, int NumTimes, struct timeval *AvgTime)
116 double meantime;
118 meantime = mean(timevaldouble(TotalTime), NumTimes);
120 doubletimeval(meantime, AvgTime);
124 void
125 sqtime(struct timeval *Time, struct timeval *SqTime)
127 double sec;
129 sec = timevaldouble(Time);
130 sec *= sec; /* square */
132 doubletimeval(sec, SqTime);
136 void
137 variancetime(struct timeval *SumTime, double SumSquareTime, int NumTimes, struct timeval *VarianceTime)
139 double result;
141 result = variance(timevaldouble(SumTime), SumSquareTime, NumTimes);
143 doubletimeval(result, VarianceTime);
147 void
148 stddevtime(struct timeval *SumTime, double SumSquareTime,
149 int NumTimes, struct timeval *StdDevTime)
151 double result;
153 result = stddev(timevaldouble(SumTime), SumSquareTime, NumTimes);
155 doubletimeval(result, StdDevTime);
158 double
159 thruputpersec(const double n, struct timeval *t)
161 double tv;
163 tv = timevaldouble(t);
164 if (tv != 0)
165 return n / timevaldouble(t);
166 else
167 return 0;