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-2009 Soeren Sonnenburg 00008 * Copyright (C) 1999-2009 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 00021 namespace shogun 00022 { 00025 class CTime : public CSGObject 00026 { 00027 public: 00032 CTime(bool start=true); 00033 virtual ~CTime(); 00034 00040 clock_t cur_runtime(bool verbose=false); 00041 00047 clock_t cur_runtime_diff(bool verbose=false); 00048 00054 float64_t cur_runtime_diff_sec(bool verbose=false); 00055 00061 float64_t start(bool verbose=false); 00062 00068 float64_t cur_time_diff(bool verbose=false); 00069 00075 float64_t time_diff_sec(bool verbose=false); 00076 00081 float64_t stop(bool verbose=false); 00082 00087 static int64_t get_runtime() 00088 { 00089 clock_t start_runtime = clock(); 00090 return( 00091 (int64_t) ((float64_t)start_runtime*100.0/(float64_t)CLOCKS_PER_SEC)); 00092 } 00093 00098 static float64_t get_curtime() 00099 { 00100 timeval tv; 00101 if (gettimeofday(&tv, NULL)==0) 00102 return tv.tv_sec+(tv.tv_usec*1e-6); 00103 else 00104 return 0.0; 00105 } 00106 00108 inline virtual const char* get_name() const { return "Time"; } 00109 00110 protected: 00112 clock_t start_runtime; 00113 00115 float64_t start_time; 00117 float64_t stop_time; 00118 }; 00119 } 00120 #endif