SHOGUN  4.1.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/config.h>
20 
21 #include <shogun/lib/common.h>
22 #include <shogun/base/SGObject.h>
23 
24 #if defined(_MSC_VER) || defined(__MINGW32__)
25 
26 #ifndef _TIMEVAL_DEFINED /* also in winsock[2].h */
27 #define _TIMEVAL_DEFINED
28 struct timeval {
29  long tv_sec;
30  long tv_usec;
31 };
32 #endif /* _TIMEVAL_DEFINED */
33 
34 int gettimeofday(struct timeval* tp, void* tzp) {
35  DWORD t;
36  t = timeGetTime();
37  tp->tv_sec = t / 1000;
38  tp->tv_usec = t % 1000;
39  /* 0 indicates that the call succeeded. */
40  return 0;
41 }
42 #endif
43 namespace shogun
44 {
47 class CTime : public CSGObject
48 {
49  public:
54  CTime(bool start=true);
55  virtual ~CTime();
56 
62  clock_t cur_runtime(bool verbose=false);
63 
69  clock_t cur_runtime_diff(bool verbose=false);
70 
77  float64_t cur_runtime_diff_sec(bool verbose=false);
78 
84  float64_t start(bool verbose=false);
85 
92  float64_t cur_time_diff(bool verbose=false);
93 
99  float64_t time_diff_sec(bool verbose=false);
100 
105  float64_t stop(bool verbose=false);
106 
112  {
113  clock_t start_runtime = clock();
114  return ((float64_t) start_runtime)/CLOCKS_PER_SEC;
115  }
116 
122  {
123  timeval tv;
124  if (gettimeofday(&tv, NULL)==0)
125  return tv.tv_sec+(tv.tv_usec*1e-6);
126  else
127  return 0.0;
128  }
129 
131  virtual const char* get_name() const { return "Time"; }
132 
133  protected:
135  clock_t start_runtime;
136 
141 };
142 }
143 #endif
Class Time that implements a stopwatch based on either cpu time or wall clock time.
Definition: Time.h:47
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:111
virtual ~CTime()
Definition: Time.cpp:29
static float64_t get_curtime()
Definition: Time.h:121
float64_t stop_time
Definition: Time.h:140
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:112
float64_t start_time
Definition: Time.h:138
double float64_t
Definition: common.h:50
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:131
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:135

SHOGUN 机器学习工具包 - 项目文档