Timer.h

00001 // Timer class
00002 
00003 /*  IIP fcgi server module
00004 
00005     Copyright (C) 2005 Ruven Pillay.
00006 
00007     This program is free software; you can redistribute it and/or modify
00008     it under the terms of the GNU General Public License as published by
00009     the Free Software Foundation; either version 2 of the License, or
00010     (at your option) any later version.
00011 
00012     This program is distributed in the hope that it will be useful,
00013     but WITHOUT ANY WARRANTY; without even the implied warranty of
00014     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015     GNU General Public License for more details.
00016 
00017     You should have received a copy of the GNU General Public License
00018     along with this program; if not, write to the Free Software
00019     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00020 */
00021 
00022 
00023 
00024 #ifndef _TIMER_H
00025 #define _TIMER_H
00026 
00027 
00028 #ifdef HAVE_SYS_TIME_H
00029 
00030 #include <sys/time.h>
00031 
00032 
00034 
00035 class Timer {
00036 
00037 
00038  private:
00039 
00041   struct timeval tv;
00042 
00044   struct timezone tz;
00045 
00047   long start_t;
00048 
00050   long start_u;
00051 
00052 
00053  public:
00054 
00056   Timer() {;};
00057 
00058 
00060 
00061   void start() {
00062     tz.tz_minuteswest = 0;
00063     if( gettimeofday( &tv, &tz ) == 0 ){
00064       start_t = tv.tv_sec;
00065       start_u = tv.tv_usec;
00066     }
00067     else start_t = start_u = 0;
00068   }
00069 
00070 
00072   long getTime() {
00073     if( gettimeofday( &tv, &tz ) == 0 ) return (tv.tv_sec - start_t) * 1000000 + (tv.tv_usec - start_u);
00074     else return 0;
00075   }
00076 
00077 
00078 };
00079 
00080 
00081 
00082 #else
00083 
00085 
00086 class Timer {
00087 
00088  public:
00089 
00091   Timer() {;};
00092 
00094   void start() {;};
00095 
00097   long getTime(){ return 0; }
00098 
00099 };
00100 
00101 
00102 #endif
00103 
00104 #endif
00105 

Generated on Fri Nov 26 16:55:07 2010 for iipsrv by  doxygen 1.5.8