SHOGUN
v3.0.0
Main Page
Related Pages
Modules
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Groups
Pages
src
shogun
lib
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/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
110
static
float64_t
get_runtime
()
111
{
112
clock_t
start_runtime
= clock();
113
return
((
float64_t
) start_runtime)/CLOCKS_PER_SEC;
114
}
115
120
static
float64_t
get_curtime
()
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
137
float64_t
start_time
;
139
float64_t
stop_time
;
140
};
141
}
142
#endif
SHOGUN
Machine Learning Toolbox - Documentation