iipsrv
0.9.9
|
00001 // Timer class 00002 00003 /* IIP fcgi server module 00004 00005 Copyright (C) 2005-2011 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 3 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 #ifndef _TIMER_H 00024 #define _TIMER_H 00025 00026 00027 #ifdef HAVE_SYS_TIME_H 00028 #include <sys/time.h> 00029 #endif 00030 00031 00032 #ifdef WIN32 00033 #include "../windows/Time.h" 00034 #endif 00035 00036 00038 00039 class Timer { 00040 00041 00042 private: 00043 00045 struct timeval tv; 00046 00048 struct timezone tz; 00049 00051 long start_t; 00052 00054 long start_u; 00055 00056 00057 public: 00058 00060 Timer() {;}; 00061 00062 00064 00065 void start() { 00066 tz.tz_minuteswest = 0; 00067 if( gettimeofday( &tv, NULL ) == 0 ){ 00068 start_t = tv.tv_sec; 00069 start_u = tv.tv_usec; 00070 } 00071 else start_t = start_u = 0; 00072 } 00073 00074 00076 long getTime() { 00077 if( gettimeofday( &tv, NULL ) == 0 ) return (tv.tv_sec - start_t) * 1000000 + (tv.tv_usec - start_u); 00078 else return 0; 00079 } 00080 00081 00082 }; 00083 00084 00085 00086 #endif 00087