Google
Web alhem.net

Ticks_i.h

Go to the documentation of this file.
00001 // Ticks_i.h
00002 /*
00003 Copyright (C) 2003  Anders Hedstrom
00004 
00005 This program is free software; you can redistribute it and/or
00006 modify it under the terms of the GNU General Public License
00007 as published by the Free Software Foundation; either version 2
00008 of the License, or (at your option) any later version.
00009 
00010 This program is distributed in the hope that it will be useful,
00011 but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 GNU General Public License for more details.
00014 
00015 You should have received a copy of the GNU General Public License
00016 along with this program; if not, write to the Free Software
00017 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00018 */
00019 
00020 #ifndef _TICKS_I_H
00021 #define _TICKS_I_H
00022 #ifndef _WIN32
00023 
00024 #include <sys/time.h>
00025 #include <unistd.h>
00026 
00027 namespace Cgi {
00028 
00029 class Ticks
00030 {
00031 public:
00032         void Start() {
00033                 struct timeval tv;
00034                 struct timezone tz;
00035                 gettimeofday(&tv,&tz);
00036                 d0 = tv.tv_sec;
00037                 d0 *= 1000000;
00038                 d0 += tv.tv_usec;
00039                 dstop = d0;
00040                 dtemp = d0;
00041         }
00042         Ticks() {
00043                 Start();
00044         }
00045         ~Ticks() {
00046         }
00047         void Stop() {
00048                 struct timeval tv;
00049                 struct timezone tz;
00050                 gettimeofday(&tv,&tz);
00051                 dstop = tv.tv_sec;
00052                 dstop *= 1000000;
00053                 dstop += tv.tv_usec;
00054         }
00055         double Time(void) {
00056                 return dstop - d0;
00057         }
00058         void Time(char *s) {
00059                 sprintf(s,"%.4f sec",Time() / 1000000);
00060         }
00061         void TempTime(char *s) {
00062                 struct timeval tv;
00063                 struct timezone tz;
00064                 double dnow;
00065                 gettimeofday(&tv,&tz);
00066                 dnow = tv.tv_sec;
00067                 dnow *= 1000000;
00068                 dnow += tv.tv_usec;
00069                 double d = dnow - dtemp;
00070                 dtemp = dnow;
00071                 sprintf(s,"%.4f sec",d / 1000000);
00072         }
00073 private:
00074         double d0;
00075         double dstop;
00076         double dtemp;
00077 };
00078 
00079 } // namespace
00080 
00081 #endif // _WIN32
00082 #endif // _TICKS_I_H

Generated for cgi++ by doxygen 1.3.7

Page, code, and content Copyright (C) 2004 by Anders Hedström