Basic Image AlgorithmS Library 2.8.0

Timing.cpp

00001 // Jan Woetzel
00002 #include "Timing.hh"
00003 
00004 #ifdef WIN32
00005 #  include <stdio.h>
00006 #  include <Windows.h>
00007 #else
00008 #  include <sys/time.h>
00009 #  include <time.h>
00010 #endif
00011 
00012 
00013 namespace BIAS {
00014 
00015 
00016 #ifdef WIN32
00017 
00018 #define Li2Double(x) ((double)((x).HighPart) * 4.294967296E9 + (double)((x).LowPart))
00019 
00020   double Realtime (void)
00021   {
00022     LARGE_INTEGER time, freq;
00023     double dtime, dfreq, res;
00024     if (QueryPerformanceCounter(&time) == 0)
00025     {
00026       DWORD err = GetLastError();
00027       LPVOID buf;
00028       FormatMessage(
00029         FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
00030         NULL,
00031         err,
00032         MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
00033         (LPTSTR) &buf,
00034         0, NULL
00035         );
00036       printf("QueryPerformanceCounter() failed with error %d: %s\n", err, buf);
00037       //BIASEXIT(1);
00038       exit(1);
00039     }
00040     if (QueryPerformanceFrequency(&freq) == 0)
00041     {
00042       DWORD err = GetLastError();
00043       LPVOID buf;
00044       FormatMessage(
00045         FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
00046         NULL,
00047         err,
00048         MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
00049         (LPTSTR) &buf,
00050         0, NULL
00051         );
00052       printf("QueryPerformanceFrequency() failed with error %d: %s\n", err, buf);
00053       //BIASEXIT(1);
00054       exit(1);
00055     }
00056     dtime = Li2Double(time);
00057     dfreq = Li2Double(freq);
00058     res = dtime / dfreq;
00059     return res;
00060   }
00061 
00062 
00063 #else // WIN32
00064 
00065   double Realtime(void)
00066   {
00067     struct timeval tv;
00068     gettimeofday(&tv, (struct timezone*)0);
00069     return ((double)tv.tv_sec + (double)tv.tv_usec / 1000000.0 );
00070   }
00071 
00072   double realtime_ (void){ 
00073     return realtime(); 
00074   }
00075 
00076 #endif // WIN32
00077 
00078 } // namespace
00079 
 All Classes Functions Variables Typedefs Enumerations Enumerator Friends