Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Timing.cpp
1 // Jan Woetzel
2 #include "Timing.hh"
3 
4 #ifdef WIN32
5 # include <stdio.h>
6 # include <Windows.h>
7 #else
8 # include <sys/time.h>
9 # include <time.h>
10 #endif
11 
12 
13 namespace BIAS {
14 
15 
16 #ifdef WIN32
17 
18 #define Li2Double(x) ((double)((x).HighPart) * 4.294967296E9 + (double)((x).LowPart))
19 
20  double Realtime (void)
21  {
22  LARGE_INTEGER time, freq;
23  double dtime, dfreq, res;
24  if (QueryPerformanceCounter(&time) == 0)
25  {
26  DWORD err = GetLastError();
27  LPVOID buf;
28  FormatMessage(
29  FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
30  NULL,
31  err,
32  MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
33  (LPTSTR) &buf,
34  0, NULL
35  );
36  printf("QueryPerformanceCounter() failed with error %d: %s\n", err, buf);
37  //BIASEXIT(1);
38  exit(1);
39  }
40  if (QueryPerformanceFrequency(&freq) == 0)
41  {
42  DWORD err = GetLastError();
43  LPVOID buf;
44  FormatMessage(
45  FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
46  NULL,
47  err,
48  MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
49  (LPTSTR) &buf,
50  0, NULL
51  );
52  printf("QueryPerformanceFrequency() failed with error %d: %s\n", err, buf);
53  //BIASEXIT(1);
54  exit(1);
55  }
56  dtime = Li2Double(time);
57  dfreq = Li2Double(freq);
58  res = dtime / dfreq;
59  return res;
60  }
61 
62 
63 #else // WIN32
64 
65  double Realtime(void)
66  {
67  struct timeval tv;
68  gettimeofday(&tv, (struct timezone*)0);
69  return ((double)tv.tv_sec + (double)tv.tv_usec / 1000000.0 );
70  }
71 
72  double realtime_ (void){
73  return realtime();
74  }
75 
76 #endif // WIN32
77 
78 } // namespace
79 
double realtime_(void)
Definition: Timing.cpp:72
double Realtime(void)
Definition: Timing.cpp:65