timer.h

00001 /***************************************************************************
00002                                 timer.h
00003                              -------------------
00004     begin                : Fri Jan 10 2003
00005     author               : Daniel Westhoff
00006     email                : westhoff@informatik.uni-hamburg.de
00007  ***************************************************************************/
00008 
00009 /***************************************************************************
00010  *                                                                         *
00011  *   This program is free software; you can redistribute it and/or modify  *
00012  *   it under the terms of the GNU General Public License as published by  *
00013  *   the Free Software Foundation; either version 2 of the License, or     *
00014  *   (at your option) any later version.                                   *
00015  *                                                                         *
00016  ***************************************************************************/
00017 
00018 
00019 #ifndef TIMER_H
00020 #define TIMER_H
00021 
00022 #include "sys/time.h"
00023 
00033 
00034 namespace TIMER {
00035 
00036         static struct timeval _tstart;
00037         static struct timezone tz;
00038 
00054 
00055   inline void SetStartTime (void)
00056     {
00057       gettimeofday (&_tstart,
00058                     &tz);
00059     }
00060 
00074 
00075   inline double TimeElapsed (void)
00076     {
00077       double t1,t2;
00078       
00079       // take the time now
00080 
00081       struct timeval tnow;
00082 
00083       gettimeofday (&tnow,
00084                     &tz);
00085 
00086       // compute times in seconds
00087 
00088       t1 = (double) _tstart.tv_sec + (double) _tstart.tv_usec/(1000*1000);
00089       
00090       t2 = (double) tnow.tv_sec + (double) tnow.tv_usec/(1000*1000);
00091 
00092       // retrun ellapsed time
00093 
00094       return t2 - t1;
00095     }
00096 
00110 
00111   inline double TimeElapsed (const struct timeval &time)
00112     {
00113       double t1,t2;
00114 
00115       // take the time now
00116 
00117       struct timeval tnow;
00118 
00119       gettimeofday (&tnow,
00120                     &tz);
00121 
00122       // compute times in seconds
00123 
00124       t1 = (double) time.tv_sec + (double) time.tv_usec/(1000*1000);
00125       
00126       t2 = (double) tnow.tv_sec + (double) tnow.tv_usec/(1000*1000);
00127 
00128       // retrun ellapsed time
00129 
00130       return t2 - t1;
00131     }
00132 
00133 } // end namespace
00134 
00135 #endif // TIMER_H


tams Tim Baier bhandlib v0.25
Generated Wed Aug 16 14:57:09 2006 by doxygen 1.4.7