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 00022 class CTime : public CSGObject 00023 { 00024 public: 00029 CTime(bool start=true); 00030 ~CTime(); 00031 00037 clock_t cur_runtime(bool verbose=false); 00038 00044 clock_t cur_runtime_diff(bool verbose=false); 00045 00051 double cur_runtime_diff_sec(bool verbose=false); 00052 00058 double start(bool verbose=false); 00059 00065 double cur_time_diff(bool verbose=false); 00066 00072 double time_diff_sec(bool verbose=false); 00073 00078 double stop(bool verbose=false); 00079 00084 static LONG get_runtime() 00085 { 00086 clock_t start_runtime = clock(); 00087 return((LONG)((double)start_runtime*100.0/(double)CLOCKS_PER_SEC)); 00088 } 00089 00094 static double get_curtime() 00095 { 00096 timeval tv; 00097 if (gettimeofday(&tv, NULL)==0) 00098 return tv.tv_sec+((double)(tv.tv_usec))/1e6; 00099 else 00100 return 0.0; 00101 } 00102 00103 protected: 00105 clock_t start_runtime; 00106 00108 double start_time; 00110 double stop_time; 00111 }; 00112 #endif