Feature Selection Toolbox FST4
UTIA · Czech Academy of Sciences
Loading...
Searching...
No Matches
stopwatch.hpp
Go to the documentation of this file.
1#ifndef FSTSTOPWATCH_H
2#define FSTSTOPWATCH_H
3 /*
27=========================================================================
28Copyright and license:
29 * FST4 software (with the exception of any bundled or externally linked
30 third-party components) is Copyright (C) 2000-present Institute of
31 Information Theory and Automation of the Czech Academy of Sciences (UTIA).
32 * FST4 is free software: you can redistribute it and/or modify it under
33 the terms of the GNU Affero General Public License as published by the
34 Free Software Foundation, version 3. The full text of the license is in
35 the file LICENSE in the distribution root and at
36 https://www.gnu.org/licenses/agpl-3.0.html.
37 * FST4 is distributed in the hope that it will be useful, but WITHOUT ANY
38 WARRANTY; without even the implied warranty of MERCHANTABILITY or
39 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
40 License for more details.
41 * Closed-source use without the AGPL's copyleft obligations requires a
42 commercial license from UTIA; in case of interest write to
43 utia@utia.cas.cz. LICENSING.md in the distribution root explains both
44 options, the contributor license agreement that every contribution
45 requires, and the contacts (technical questions and pull requests:
46 somol@utia.cas.cz, with "FST" in the subject line).
47========================================================================== */
48
49#include <iostream>
50#include <ctime>
51#ifdef FST_THREADED
52#include <mutex>
53#endif
54#include "error.hpp"
55#include "global.hpp"
56
57/*============== Template parameter type naming conventions ==============
58--------- Numeric types: -------------------------------------------------
59DATATYPE - data sample values - usually real numbers (but may be integers
60 in text processing etc.)
61REALTYPE - must be real numbers - for representing intermediate results of
62 calculations like mean, covariance etc.
63IDXTYPE - index values for enumeration of data samples - (nonnegative) integers,
64 extent depends on numbers of samples in data
65DIMTYPE - index values for enumeration of features (dimensions), or classes (not
66 class sizes) - (nonnegative) integers, usually lower extent than IDXTYPE,
67 but be aware of expressions like _classes*_features*_features !
68 in linearized representations of feature matrices for all classes
69BINTYPE - feature selection marker type - represents ca. <10 different feature
70 states (selected, deselected, sel./desel. temporarily 1st nested loop, 2nd...)
71RETURNTYPE - criterion value: real value, but may be extended in future to support
72 multiple values
73--------- Class types: ---------------------------------------------------
74SUBSET - class of class type Subset
75CLASSIFIER - class implementing interface defined in abstract class Classifier
76EVALUATOR - class implementing interface defined in abstract class Sequential_Step
77DISTANCE - class implementing interface defined in abstract class Distance
78DATAACCESSOR - class implementing interface defined in abstract class Data_Accessor
79INTERVALCONTAINER - class of class type Data_Intervaller
80CONTAINER - STL container of class type Data_Interval
81========================================================================== */
82
83namespace FST {
84
92class StopWatch {
94 friend std::ostream& operator<<(std::ostream& os, const StopWatch& sw);
95public:
96 StopWatch() {time(&first); notify("StopWatch constructor.");}
97 ~StopWatch() {notify("StopWatch destructor.");}
99 double time_elapsed() const // in seconds
100 {
101#ifdef FST_THREADED
102 std::unique_lock<std::mutex> locktimeelapsed(timeelapsed_mutex);
103#endif
104 time_t current;
105 time(&current);
106 return difftime(current,first);
107 }
108
110 std::ostream& print(std::ostream& os) const
111 {
112 long dif=long(time_elapsed());
113 long dif2=dif;
114 int days=dif/(60*60*24); dif%=60*60*24;
115 int hours=dif/(60*60); dif%=60*60;
116 int minutes=dif/60; dif%=60;
117 int seconds=dif;
118 os << "StopWatch time: "<< days << ":";
119 if(hours<10) os << "0";
120 os << hours << ":";
121 if(minutes<10) os << "0";
122 os << minutes << ":";
123 if(seconds<10) os << "0";
124 os << seconds << " (equals " << dif2 << " seconds)";
125 return os;
126 }
127private:
128 time_t first;
129#ifdef FST_THREADED
130 mutable std::mutex timeelapsed_mutex;
131#endif
132};
133
135inline std::ostream& operator<<(std::ostream& os, const StopWatch& sw) {
136 return sw.print(os);
137}
138
139} // namespace
140#endif // FSTSTOPWATCH_H ///:~
friend std::ostream & operator<<(std::ostream &os, const StopWatch &sw)
Streams a StopWatch's print() (formatted elapsed time) to os.
Definition stopwatch.hpp:135
double time_elapsed() const
Returns the number of whole seconds elapsed since construction (wall-clock via time(),...
Definition stopwatch.hpp:99
std::mutex timeelapsed_mutex
serializes concurrent time_elapsed() calls on one StopWatch (FST_THREADED only); first itself is writ...
Definition stopwatch.hpp:130
time_t first
wall-clock time captured at construction, the time_elapsed() baseline
Definition stopwatch.hpp:128
std::ostream & print(std::ostream &os) const
Writes elapsed time formatted as "StopWatch time: D:HH:MM:SS (equals N seconds)" to os.
Definition stopwatch.hpp:110
FST4 specific error passing class.
Global definitions.
The Feature Selection Toolbox 4 library: every library component – data access, criteria and classifi...
Definition data_accessor.hpp:80
void notify(const std::string msg)
Prints msg followed by a newline via syncout::print(); a no-op unless the preprocessor macro DEBUG is...
Definition global.hpp:112
std::ostream & operator<<(std::ostream &os, const Data_Intervaller< CONTAINER, IDXTYPE > &ia)
Streams every contained interval as "si:<startidx>, c:<count>" lines to os.
Definition data_intervaller.hpp:152
Copyright © 2000–present ÚTIA, Institute of Information Theory and Automation of the Czech Academy of Sciences · Contacts · This site sets no cookies and uses no analytics.