SHOGUN  v3.2.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
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 #ifndef _WIN32
00015 #include <sys/time.h>
00016 #endif
00017 #include <time.h>
00018 
00019 #include <shogun/lib/common.h>
00020 #include <shogun/io/SGIO.h>
00021 #include <shogun/base/SGObject.h>
00022 
00023 #if defined(_MSC_VER) || defined(__MINGW32__)
00024 
00025 #ifndef _TIMEVAL_DEFINED /* also in winsock[2].h */
00026 #define _TIMEVAL_DEFINED
00027 struct timeval {
00028     long tv_sec;
00029     long tv_usec;
00030 };
00031 #endif /* _TIMEVAL_DEFINED */
00032 
00033 int gettimeofday(struct timeval* tp, void* tzp) {
00034     DWORD t;
00035     t = timeGetTime();
00036     tp->tv_sec = t / 1000;
00037     tp->tv_usec = t % 1000;
00038     /* 0 indicates that the call succeeded. */
00039     return 0;
00040 }
00041 #endif
00042 namespace shogun
00043 {
00046 class CTime : public CSGObject
00047 {
00048     public:
00053         CTime(bool start=true);
00054         virtual ~CTime();
00055 
00061         clock_t cur_runtime(bool verbose=false);
00062 
00068         clock_t cur_runtime_diff(bool verbose=false);
00069 
00076         float64_t cur_runtime_diff_sec(bool verbose=false);
00077 
00083         float64_t start(bool verbose=false);
00084 
00091         float64_t cur_time_diff(bool verbose=false);
00092 
00098         float64_t time_diff_sec(bool verbose=false);
00099 
00104         float64_t stop(bool verbose=false);
00105 
00110         static float64_t get_runtime()
00111         {
00112             clock_t start_runtime = clock();
00113             return ((float64_t) start_runtime)/CLOCKS_PER_SEC;
00114         }
00115 
00120         static float64_t get_curtime()
00121         {
00122             timeval tv;
00123             if (gettimeofday(&tv, NULL)==0)
00124                 return tv.tv_sec+(tv.tv_usec*1e-6);
00125             else
00126                 return 0.0;
00127         }
00128 
00130         virtual const char* get_name() const { return "Time"; }
00131 
00132     protected:
00134         clock_t start_runtime;
00135 
00137         float64_t start_time;
00139         float64_t stop_time;
00140 };
00141 }
00142 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

SHOGUN Machine Learning Toolbox - Documentation