00001 //=========================================================================== 00002 // GoTools - SINTEF Geometry Tools version 1.1 00003 // 00004 // GoTools module: CORE 00005 // 00006 // Copyright (C) 2000-2007 SINTEF ICT, Applied Mathematics, Norway. 00007 // 00008 // This program is free software; you can redistribute it and/or 00009 // modify it under the terms of the GNU General Public License 00010 // as published by the Free Software Foundation version 2 of the License. 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., 00020 // 59 Temple Place - Suite 330, 00021 // Boston, MA 02111-1307, USA. 00022 // 00023 // Contact information: E-mail: tor.dokken@sintef.no 00024 // SINTEF ICT, Department of Applied Mathematics, 00025 // P.O. Box 124 Blindern, 00026 // 0314 Oslo, Norway. 00027 // 00028 // Other licenses are also available for this software, notably licenses 00029 // for: 00030 // - Building commercial software. 00031 // - Building software whose source code you wish to keep private. 00032 //=========================================================================== 00033 #ifndef CPUCLOCK_H 00034 #define CPUCLOCK_H 00035 00036 #include <string> 00037 #include "timeutils.h" 00038 00039 namespace Go { 00042 00043 /*<CPUclock:*/ 00045 class CPUclock 00046 { 00047 double last; // previous clock value 00048 double now; // present clock value 00049 double diff; // diff = now - last 00050 00051 void swap();// last = now 00052 void subt();// subtract: now - last, store in diff 00053 00054 public: 00056 CPUclock (); 00057 00060 double getInterval (); // returns user time 00061 // double getInterval2 (); // returns user time + system time 00062 00065 void initTime () { getInterval(); } 00066 00067 // string report (const string& message); 00068 00070 double getTime (); 00071 }; 00072 00074 };// namespace Go 00075 /*>CPUclock:*/ 00076 00077 /*Class:CPUclock 00078 00079 NAME: CPUclock - measures the CPU time in C++ programs 00080 00081 SYNTAX: @CPUclock 00082 00083 00084 KEYWORDS: 00085 00086 CPU time, clock 00087 00088 00089 DESCRIPTION: 00090 00091 One can get the user time in absolute seconds, or the length of intervals 00092 can be measured (in seconds). 00093 00094 "getTime" - returns time in seconds since January 1, 1970 00095 00096 "initTime" - start measuring the length of an interval (typically called 00097 prior to the computational job to be measured). In fact, 00098 "initTime" is just a call to "getInterval" - the function 00099 was for making programs easier to read. 00100 00101 "getInterval" - returns the length of the user time interval (in seconds) 00102 between the present call to getInterval and the last call 00103 to initTime or to getInterval 00104 00105 "getInterval2" - as "getInterval", but the user time plus the system time 00106 is returned. 00107 00108 "report" - returns a string ("String") containing a message (f.ex. where in 00109 the program the "report" function was called) and the user and 00110 system time since last call to "initTime" or "getInterval" 00111 (or "getInterval2"). 00112 00113 SEE ALSO: 00114 00115 "time.h", "sys/times.h" 00116 00117 DEVELOPED BY: 00118 00119 SINTEF Applied Mathematics, Oslo, Norway, and 00120 University of Oslo, Dept. of Mathematics, Norway 00121 00122 AUTHOR: 00123 00124 Hans Petter Langtangen, SINTEF/UiO 00125 00126 End: 00127 */ 00128 00129 00130 00131 00132 #endif 00133 00134 00135 00136 /* LOG HISTORY of this file: 00137 00138 $Log: CPUclock.h,v $ 00139 Revision 1.7 2005/06/09 07:29:33 oan 00140 removed some deprecated files 00141 00142 Revision 1.6 2004/04/02 06:06:38 bsp 00143 Bug fix in getTime() 00144 00145 Revision 1.5 2004/01/14 11:19:19 bsp 00146 Added doxygen code 00147 00148 Revision 1.4 2002/08/15 15:05:26 sbr 00149 WinNT compilation fix. 00150 00151 Revision 1.3 2002/04/26 09:30:59 ers 00152 Moved CPUclock from parametrization to utils 00153 00154 Revision 1.1 2000/10/20 10:28:38 afr 00155 First commit. 00156 00157 Revision 1.1 2000/07/06 07:17:27 afr 00158 Added a few new files and changed GoHandle a bit. 00159 00160 * Revision 1.14 1996/11/15 10:58:31 job 00161 * Version 2.4.0 00162 * 00163 */ 00164