Time.h

Go to the documentation of this file.
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 
00055         float64_t cur_runtime_diff_sec(bool verbose=false);
00056 
00062         float64_t start(bool verbose=false);
00063 
00070         float64_t cur_time_diff(bool verbose=false);
00071 
00077         float64_t time_diff_sec(bool verbose=false);
00078 
00083         float64_t stop(bool verbose=false);
00084 
00089         static float64_t get_runtime()
00090         {
00091             clock_t start_runtime = clock();
00092             return ((float64_t) start_runtime)/CLOCKS_PER_SEC;
00093         }
00094 
00099         static float64_t get_curtime()
00100         {
00101             timeval tv;
00102             if (gettimeofday(&tv, NULL)==0)
00103                 return tv.tv_sec+(tv.tv_usec*1e-6);
00104             else
00105                 return 0.0;
00106         }
00107 
00109         inline virtual const char* get_name() const { return "Time"; }
00110 
00111     protected:
00113         clock_t start_runtime;
00114 
00116         float64_t start_time;
00118         float64_t stop_time;
00119 };
00120 }
00121 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

SHOGUN Machine Learning Toolbox - Documentation