/vol/vipdata/irtk/common++/include/irtkTimer.h

00001 /*=========================================================================
00002 
00003   Library   : Image Registration Toolkit (IRTK)
00004   Module    : $Id: irtkTimer.h 2 2008-12-23 12:40:14Z dr $
00005   Copyright : Imperial College, Department of Computing
00006               Visual Information Processing (VIP), 2008 onwards
00007   Date      : $Date: 2008-12-23 12:40:14 +0000 (Tue, 23 Dec 2008) $
00008   Version   : $Revision: 2 $
00009   Changes   : $Author: dr $
00010 
00011 =========================================================================*/
00012 
00013 #ifndef _IRTKTIMER_H
00014 
00015 #define _IRTKTIMER_H
00016 
00017 #include <time.h>
00018 
00019 #ifndef WIN32
00020 #include <sys/times.h>
00021 #endif
00022 
00023 // Uncomment to check for normalization of tms_utime, see also <limits.h>
00024 // #include <unistd.h>
00025 
00026 // Local includes
00027 #include <irtkObject.h>
00028 
00029 class irtkTimer : public irtkObject
00030 {
00031 
00032 public:
00033 
00035   irtkTimer() {
00036     // Uncomment to check for normalization of tms_utime //
00037     // cerr << sysconf(3) << " " << CLK_TCK << endl;
00038     this->Reset();
00039   };
00040 
00042   virtual ~irtkTimer() {};
00043 
00045   float Report();
00046 
00048   void  Reset();
00049 
00050 private:
00051 
00052 #ifndef WIN32
00053 
00055   long       _usr_time;
00056 
00058   struct tms _cpu_time;
00059 
00060 #endif
00061 
00062 };
00063 
00064 inline float irtkTimer::Report()
00065 {
00066 #ifndef WIN32
00067   times(&_cpu_time);
00068   _usr_time += _cpu_time.tms_utime;
00069   return _usr_time/(float)CLOCKS_PER_SEC;
00070 #else
00071   return 0;
00072 #endif
00073 }
00074 
00075 inline void irtkTimer::Reset()
00076 {
00077 #ifndef WIN32
00078   times(&_cpu_time);
00079   _usr_time = -_cpu_time.tms_utime;
00080 #endif
00081 }
00082 
00083 #endif