1 #include <stdio.h>
2 #ifdef CYGWIN
3 #include <windows.h>
4 #else
5 #include <time.h>
6 #include <sys/time.h>
7 #endif
8 
9 void InitTime();
10 unsigned long GetTimeElapsed();
11 
12 
13 #ifdef CYGWIN
14 double frequency;
15 unsigned long StartTime;
16 #else
17 struct timeval StartTime;
18 #endif
19 
20 
InitTime()21 void InitTime()
22 {
23 #ifdef CYGWIN
24   LARGE_INTEGER CpuFreq, TimeCount;
25 
26   QueryPerformanceFrequency(&CpuFreq);
27   frequency = (double)CpuFreq.LowPart/1000000.0;
28   QueryPerformanceCounter(&TimeCount);
29   StartTime = TimeCount.LowPart;
30 #else
31   struct timezone tz;
32 
33   gettimeofday(&StartTime, &tz);
34 #endif
35 }
36 
37 
38 // Gets the time elapsed from when the server started, in microseconds
GetTimeElapsed()39 unsigned long GetTimeElapsed()
40 {
41 #ifdef CYGWIN
42   LARGE_INTEGER TimeCount;
43 
44   double TimeElapsed;
45 
46   QueryPerformanceCounter(&TimeCount);
47   TimeElapsed=(double)(TimeCount.LowPart-StartTime)/frequency;
48   return((unsigned long)TimeElapsed);
49 #else
50   struct timezone tz;
51   struct timeval now;
52 
53   gettimeofday(&now, &tz);
54 
55   return((now.tv_sec-StartTime.tv_sec)*1000000+
56          (now.tv_usec-StartTime.tv_usec));
57 #endif
58 }
59