SHOGUN  6.0.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules
Time.h
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or modify
3  * it under the terms of the GNU General Public License as published by
4  * the Free Software Foundation; either version 3 of the License, or
5  * (at your option) any later version.
6  *
7  * Written (W) 1999-2009 Soeren Sonnenburg
8  * Copyright (C) 1999-2009 Fraunhofer Institute FIRST and Max-Planck-Society
9  */
10 
11 #ifndef __TIME_H__
12 #define __TIME_H__
13 
14 #ifndef _WIN32
15 #include <sys/time.h>
16 #endif
17 #include <time.h>
18 
19 #include <shogun/lib/config.h>
20 
21 #include <shogun/lib/common.h>
22 #include <shogun/base/SGObject.h>
23 
24 #if defined(_MSC_VER) || defined(__MINGW32__) || defined(__MINGW64__)
25 
26 #ifdef __MINGW32__
27 #ifndef _TIMEVAL_DEFINED
28 #define _TIMEVAL_DEFINED
29 struct timeval {
30  long tv_sec;
31  long tv_usec;
32 };
33 #endif /* _TIMEVAL_DEFINED */
34 #endif /* __MINGW32__ */
35 
36 int gettimeofday(struct timeval* tp, void* tzp);
37 #endif
38 namespace shogun
39 {
42 class CTime : public CSGObject
43 {
44  public:
49  CTime(bool start=true);
50  virtual ~CTime();
51 
57  clock_t cur_runtime(bool verbose=false);
58 
64  clock_t cur_runtime_diff(bool verbose=false);
65 
72  float64_t cur_runtime_diff_sec(bool verbose=false);
73 
79  float64_t start(bool verbose=false);
80 
87  float64_t cur_time_diff(bool verbose=false);
88 
94  float64_t time_diff_sec(bool verbose=false);
95 
100  float64_t stop(bool verbose=false);
101 
107  {
108  clock_t start_runtime = clock();
109  return ((float64_t) start_runtime)/CLOCKS_PER_SEC;
110  }
111 
117  {
118  timeval tv;
119  if (gettimeofday(&tv, NULL)==0)
120  return tv.tv_sec+(tv.tv_usec*1e-6);
121  else
122  return 0.0;
123  }
124 
126  virtual const char* get_name() const { return "Time"; }
127 
128  protected:
130  clock_t start_runtime;
131 
136 };
137 }
138 #endif
Class Time that implements a stopwatch based on either cpu time or wall clock time.
Definition: Time.h:42
clock_t cur_runtime_diff(bool verbose=false)
Definition: Time.cpp:41
clock_t cur_runtime(bool verbose=false)
Definition: Time.cpp:33
float64_t stop(bool verbose=false)
Definition: Time.cpp:86
static float64_t get_runtime()
Definition: Time.h:106
virtual ~CTime()
Definition: Time.cpp:29
static float64_t get_curtime()
Definition: Time.h:116
float64_t stop_time
Definition: Time.h:135
float64_t time_diff_sec(bool verbose=false)
Definition: Time.cpp:77
float64_t cur_time_diff(bool verbose=false)
Definition: Time.cpp:68
Class SGObject is the base class of all shogun objects.
Definition: SGObject.h:125
float64_t start_time
Definition: Time.h:133
double float64_t
Definition: common.h:60
float64_t start(bool verbose=false)
Definition: Time.cpp:59
all of classes and functions are contained in the shogun namespace
Definition: class_list.h:18
virtual const char * get_name() const
Definition: Time.h:126
float64_t cur_runtime_diff_sec(bool verbose=false)
Definition: Time.cpp:49
CTime(bool start=true)
Definition: Time.cpp:18
clock_t start_runtime
Definition: Time.h:130

SHOGUN Machine Learning Toolbox - Documentation