00001 /* 00002 * This program is free software; you can redistribute it and/or modify 00003 * it under the terms of the GNU General Public License as published by 00004 * the Free Software Foundation; either version 3 of the License, or 00005 * (at your option) any later version. 00006 * 00007 * Written (W) 1999-2008 Soeren Sonnenburg 00008 * Copyright (C) 1999-2008 Fraunhofer Institute FIRST and Max-Planck-Society 00009 */ 00010 00011 #ifndef __TIME_H__ 00012 #define __TIME_H__ 00013 00014 #include <sys/time.h> 00015 #include <time.h> 00016 00017 #include "lib/common.h" 00018 #include "lib/io.h" 00019 #include "base/SGObject.h" 00020 00023 class CTime : public CSGObject 00024 { 00025 public: 00030 CTime(bool start=true); 00031 ~CTime(); 00032 00038 clock_t cur_runtime(bool verbose=false); 00039 00045 clock_t cur_runtime_diff(bool verbose=false); 00046 00052 float64_t cur_runtime_diff_sec(bool verbose=false); 00053 00059 float64_t start(bool verbose=false); 00060 00066 float64_t cur_time_diff(bool verbose=false); 00067 00073 float64_t time_diff_sec(bool verbose=false); 00074 00079 float64_t stop(bool verbose=false); 00080 00085 static int64_t get_runtime() 00086 { 00087 clock_t start_runtime = clock(); 00088 return( 00089 (int64_t) ((float64_t)start_runtime*100.0/(float64_t)CLOCKS_PER_SEC)); 00090 } 00091 00096 static float64_t get_curtime() 00097 { 00098 timeval tv; 00099 if (gettimeofday(&tv, NULL)==0) 00100 return (float64_t) (tv.tv_sec+((double)(tv.tv_usec))/1e6); 00101 else 00102 return 0.0; 00103 } 00104 00105 protected: 00107 clock_t start_runtime; 00108 00110 float64_t start_time; 00112 float64_t stop_time; 00113 }; 00114 #endif