GEL  2
GEL is a library for Geometry and Linear Algebra
/Users/jab/Documents/Teaching/02585/GEL2_and_demos/GEL/src/Util/Timer.h
00001 #ifndef __UTIL_OSTIMER_H__
00002 #define __UTIL_OSTIMER_H__
00003 
00004 // Created by bdl 5. april 2002
00005 // The purpose of this file is to make a timer function that is as 
00006 // precise as posible on any given platform
00007 #if (_MSC_VER >= 1200)
00008 #pragma warning (disable: 4244)
00009 #endif
00010 #ifdef WIN32
00011 #include <windows.h>
00012 static LARGE_INTEGER    largeInteger;
00013 #else
00014 #include <sys/time.h>
00015 #endif
00016 
00017 namespace Util{
00018         class Timer {
00019 #ifdef WIN32
00020                 double freq;
00021                 double start_count;
00022 #else
00023                 timeval start_time;
00024 #endif
00025         public:
00026                 void start() {
00027 #ifdef WIN32
00028                         QueryPerformanceFrequency(&largeInteger);
00029                         freq = largeInteger.QuadPart;
00030                         QueryPerformanceCounter(&largeInteger);
00031                         start_count = largeInteger.QuadPart;
00032 #else
00033                         gettimeofday(&start_time,0);
00034 #endif
00035                 }
00036 
00037                 float get_secs() {
00038 #ifdef WIN32
00039                         QueryPerformanceCounter(&largeInteger);
00040                         double now_count = largeInteger.QuadPart;
00041                         return (float)((now_count-start_count)/freq);
00042 #else
00043                         timeval now;
00044                         gettimeofday(&now,0);
00045                         return (now.tv_sec-start_time.tv_sec) + 
00046                                 (now.tv_usec-start_time.tv_usec)/1.0e6;
00047 #endif
00048                 }
00049         };
00050 }
00051 
00052 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations