Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   File Members  

timer.hpp

Go to the documentation of this file.
00001 /*
00002  * Equation Cruncher
00003  * Copyright (C) 2004  Dhruv Matani(dhruvbird@yahoo.com)
00004  * 
00005  * 
00006  * This program is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU General Public License as
00008  * published by the Free Software Foundation; either version 2 of the
00009  * License, or (at your option) any later version.
00010  * 
00011  * This program is distributed in the hope that it will be useful, but
00012  * WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  * General Public License for more details.
00015  * 
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software
00018  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00019  * USA
00020  */
00021 
00022 #if !defined EC_TIMER_HPP
00023 #define EC_TIMER_HPP
00024 
00025 #include <sys/times.h>
00026 
00034 namespace eqn_cruncher
00035 {
00041   class timer
00042   {
00044     clock_t     elapsed_begin;
00046     clock_t     elapsed_end;
00049     tms         tms_begin;
00052     tms         tms_end;
00053     
00054   public:
00058     timer() 
00059     { this->clear(); }
00060 
00061 
00066     void 
00067     clear()
00068     {
00069       elapsed_begin = 0;
00070       elapsed_end = 0;
00071       memset(&tms_begin, 0, sizeof(tms));
00072       memset(&tms_end, 0, sizeof(tms));
00073     }
00074 
00075 
00079     void
00080     start()
00081     { elapsed_begin = times(&tms_begin); }
00082 
00083 
00087     void
00088     stop()
00089     { elapsed_end = times(&tms_end); }
00090 
00091 
00098     size_t
00099     real_time() const
00100     { return elapsed_end - elapsed_begin; }
00101 
00102 
00109     size_t
00110     user_time() const
00111     { return tms_end.tms_utime - tms_begin.tms_utime; }
00112 
00113 
00120     size_t
00121     system_time() const
00122     { return tms_end.tms_stime - tms_begin.tms_stime; }
00123   };
00124 }
00125 
00126 #endif // EC_TIMER_HPP

Generated on Mon Oct 11 13:09:26 2004 for Equation Cruncher by doxygen1.2.18