libcrn  3.9.5
A document image processing library
•All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
CRNTimer.h
Go to the documentation of this file.
1 /* Copyright 2009-2015 INSA Lyon, CoReNum, Université Paris Descartes
2  *
3  * This file is part of libcrn.
4  *
5  * libcrn is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU Lesser General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * libcrn is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with libcrn. If not, see <http://www.gnu.org/licenses/>.
17  *
18  * file: CRNTimer.h
19  * \author Yann LEYDIER
20  */
21 
22 #ifndef CRNTimer_HEADER
23 #define CRNTimer_HEADER
24 
25 #include <CRNString.h>
26 #include <map>
27 
28 namespace crn
29 {
39  class Timer
40  {
41  public:
42  /***********************************************************************/
43  /* Simple unique stopwatch *********************************************/
44  /***********************************************************************/
46  static void Start();
48  static double Stop();
49 
50  /***********************************************************************/
51  /* Full stopwatch that can be used in parallel *************************/
52  /***********************************************************************/
54  static void Start(const String &timername);
56  static double Split(const String &timername, const String &splitname);
58  static String Stats(const String &timername);
60  static void Destroy(const String &timername);
61 
62  private:
64  Timer() {}
66  static double getTime();
67 
70  using StopTime = std::pair<String, double>;
72  struct StopWatch
73  {
74  std::vector<StopTime> stops;
75  double t0;
76  };
78  static std::map<String, StopWatch> stopwatches;
79  };
80 }
81 
82 #endif
83 
84 
A class to measure time.
Definition: CRNTimer.h:39
A UTF32 character string class.
Definition: CRNString.h:61
static String Stats(const String &timername)
Dumps statistics to a string.
Definition: CRNTimer.cpp:90
static double Split(const String &timername, const String &splitname)
Records time in a stopwatch.
Definition: CRNTimer.cpp:71
static void Destroy(const String &timername)
Frees a stopwatch.
Definition: CRNTimer.cpp:125
static double Stop()
Stops the quick stopwatch.
Definition: CRNTimer.cpp:146
static void Start()
Starts the quick stopwatch.
Definition: CRNTimer.cpp:136