00001 /* 00002 * 00003 * Copyright (C) 1997-2010, OFFIS e.V. 00004 * All rights reserved. See COPYRIGHT file for details. 00005 * 00006 * This software and supporting documentation were developed by 00007 * 00008 * OFFIS e.V. 00009 * R&D Division Health 00010 * Escherweg 2 00011 * D-26121 Oldenburg, Germany 00012 * 00013 * 00014 * Module: ofstd 00015 * 00016 * Author: Joerg Riesmeier 00017 * 00018 * Purpose: Class for measurement of time (Header) 00019 * 00020 * Last Update: $Author: joergr $ 00021 * Update Date: $Date: 2010-10-14 13:15:50 $ 00022 * CVS/RCS Revision: $Revision: 1.13 $ 00023 * Status: $State: Exp $ 00024 * 00025 * CVS/RCS Log at end of file 00026 * 00027 */ 00028 00029 00030 #ifndef OFTIMER_H 00031 #define OFTIMER_H 00032 00033 #include "dcmtk/config/osconfig.h" 00034 #include "dcmtk/ofstd/ofcast.h" 00035 00036 #ifdef HAVE_WINDOWS_H 00037 #include <windows.h> 00038 #else /* UNIX */ 00039 #include <sys/time.h> 00040 #endif 00041 00042 #define INCLUDE_CSTDDEF /* For NULL */ 00043 #include "dcmtk/ofstd/ofstdinc.h" 00044 00045 00046 /*---------------------* 00047 * class declaration * 00048 *---------------------*/ 00049 00053 class OFTimer 00054 { 00055 00056 public: 00057 00060 OFTimer() 00061 : Start(getTime()) 00062 { 00063 } 00064 00067 inline void reset() 00068 { 00069 Start = getTime(); 00070 } 00071 00077 inline double getDiff() const 00078 { 00079 return getTime() - Start; 00080 } 00081 00088 inline static double getDiff(double start) 00089 { 00090 return getTime() - start; 00091 } 00092 00097 inline static double getTime() 00098 { 00099 #ifdef HAVE_WINDOWS_H 00100 return OFstatic_cast(double, GetTickCount()) / 1000; 00101 #else /* tested on solaris */ 00102 timeval c_time; 00103 gettimeofday(&c_time, NULL); 00104 return OFstatic_cast(double, c_time.tv_sec) + OFstatic_cast(double, c_time.tv_usec) / 1000000; 00105 #endif 00106 } 00107 00108 00109 private: 00110 00112 double Start; 00113 }; 00114 00115 00116 #endif 00117 00118 00119 /* 00120 * 00121 * CVS/RCS Log: 00122 * $Log: oftimer.h,v $ 00123 * Revision 1.13 2010-10-14 13:15:50 joergr 00124 * Updated copyright header. Added reference to COPYRIGHT file. 00125 * 00126 * Revision 1.12 2010-03-01 09:08:51 uli 00127 * Removed some unnecessary include directives in the headers. 00128 * 00129 * Revision 1.11 2005-12-08 16:06:10 meichel 00130 * Changed include path schema for all DCMTK header files 00131 * 00132 * Revision 1.10 2003/12/05 10:37:41 joergr 00133 * Removed leading underscore characters from preprocessor symbols (reserved 00134 * symbols). Updated copyright date where appropriate. 00135 * 00136 * Revision 1.9 2003/07/09 13:57:43 meichel 00137 * Adapted type casts to new-style typecast operators defined in ofcast.h 00138 * 00139 * Revision 1.8 2001/06/01 15:51:36 meichel 00140 * Updated copyright header 00141 * 00142 * Revision 1.7 2000/03/08 16:36:03 meichel 00143 * Updated copyright header. 00144 * 00145 * Revision 1.6 2000/02/02 10:56:25 joergr 00146 * Removed space characters before preprocessor directives. 00147 * 00148 * Revision 1.5 1999/04/29 13:45:00 joergr 00149 * Added DOC++ comments. 00150 * 00151 * Revision 1.4 1999/04/21 13:01:44 meichel 00152 * ofstd/include/oftimer.h 00153 * 00154 * Revision 1.3 1999/02/05 14:07:23 joergr 00155 * Introduced new preprocessor definition HAVE_WINDOWS_H. 00156 * 00157 * Revision 1.2 1999/01/20 15:56:12 joergr 00158 * Minor changes to avoid compiler warnings (gcc 2.8.1 with additional 00159 * options). 00160 * 00161 * Revision 1.1 1999/01/20 14:27:02 joergr 00162 * Added class for measurement of time. 00163 * 00164 * 00165 */