00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef WIN32
00019
00020 #include <unistd.h>
00021 #include <sys/types.h>
00022 #include <sys/times.h>
00023 #include <sys/param.h>
00024 #ifndef HZ
00025 #define HZ 60
00026 #endif
00027 typedef struct tms mytime_t;
00028 #define GET_TIME(S) times(&(S))
00029 #define DIFF_IN_SECS(S,T) ((S.tms_utime + S.tms_stime - T.tms_utime - T.tms_stime)/(double)HZ)
00030
00031 #else
00032
00033 #include <time.h>
00034 typedef clock_t mytime_t;
00035 #define GET_TIME(S) S = clock()
00036 #define DIFF_IN_SECS(S,T) ((S - T) / (double)CLOCKS_PER_SEC)
00037
00038 #endif
00039
00040
00041 static mytime_t T;
00042
00043 void start_timer(void)
00044 {
00045 GET_TIME(T);
00046 }
00047
00048 double elapsed_sec(void)
00049 {
00050 mytime_t S;
00051 double rv;
00052
00053 GET_TIME(S);
00054 rv = DIFF_IN_SECS(S, T);
00055 return rv;
00056 }