SHOGUN  v3.2.0
 全部  命名空间 文件 函数 变量 类型定义 枚举 枚举值 友元 宏定义 
Time.h
浏览该文件的文档.
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/common.h>
20 #include <shogun/io/SGIO.h>
21 #include <shogun/base/SGObject.h>
22 
23 #if defined(_MSC_VER) || defined(__MINGW32__)
24 
25 #ifndef _TIMEVAL_DEFINED /* also in winsock[2].h */
26 #define _TIMEVAL_DEFINED
27 struct timeval {
28  long tv_sec;
29  long tv_usec;
30 };
31 #endif /* _TIMEVAL_DEFINED */
32 
33 int gettimeofday(struct timeval* tp, void* tzp) {
34  DWORD t;
35  t = timeGetTime();
36  tp->tv_sec = t / 1000;
37  tp->tv_usec = t % 1000;
38  /* 0 indicates that the call succeeded. */
39  return 0;
40 }
41 #endif
42 namespace shogun
43 {
46 class CTime : public CSGObject
47 {
48  public:
53  CTime(bool start=true);
54  virtual ~CTime();
55 
61  clock_t cur_runtime(bool verbose=false);
62 
68  clock_t cur_runtime_diff(bool verbose=false);
69 
76  float64_t cur_runtime_diff_sec(bool verbose=false);
77 
83  float64_t start(bool verbose=false);
84 
91  float64_t cur_time_diff(bool verbose=false);
92 
98  float64_t time_diff_sec(bool verbose=false);
99 
104  float64_t stop(bool verbose=false);
105 
111  {
112  clock_t start_runtime = clock();
113  return ((float64_t) start_runtime)/CLOCKS_PER_SEC;
114  }
115 
121  {
122  timeval tv;
123  if (gettimeofday(&tv, NULL)==0)
124  return tv.tv_sec+(tv.tv_usec*1e-6);
125  else
126  return 0.0;
127  }
128 
130  virtual const char* get_name() const { return "Time"; }
131 
132  protected:
134  clock_t start_runtime;
135 
140 };
141 }
142 #endif
Class Time that implements a stopwatch based on either cpu time or wall clock time.
Definition: Time.h:46
clock_t cur_runtime_diff(bool verbose=false)
Definition: Time.cpp:40
clock_t cur_runtime(bool verbose=false)
Definition: Time.cpp:32
float64_t stop(bool verbose=false)
Definition: Time.cpp:85
static float64_t get_runtime()
Definition: Time.h:110
virtual ~CTime()
Definition: Time.cpp:28
static float64_t get_curtime()
Definition: Time.h:120
float64_t stop_time
Definition: Time.h:139
float64_t time_diff_sec(bool verbose=false)
Definition: Time.cpp:76
float64_t cur_time_diff(bool verbose=false)
Definition: Time.cpp:67
Class SGObject is the base class of all shogun objects.
Definition: SGObject.h:102
float64_t start_time
Definition: Time.h:137
double float64_t
Definition: common.h:48
float64_t start(bool verbose=false)
Definition: Time.cpp:58
all of classes and functions are contained in the shogun namespace
Definition: class_list.h:16
virtual const char * get_name() const
Definition: Time.h:130
float64_t cur_runtime_diff_sec(bool verbose=false)
Definition: Time.cpp:48
CTime(bool start=true)
Definition: Time.cpp:17
clock_t start_runtime
Definition: Time.h:134

SHOGUN Machine Learning Toolbox - Documentation