Geogram Version 1.8.5
A programming library of geometric algorithms
Loading...
Searching...
No Matches
stopwatch.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2000-2022 Inria
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 *
8 * * Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
13 * * Neither the name of the ALICE Project-Team nor the names of its
14 * contributors may be used to endorse or promote products derived from this
15 * software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
21 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 * POSSIBILITY OF SUCH DAMAGE.
28 *
29 * Contact: Bruno Levy
30 *
31 * https://www.inria.fr/fr/bruno-levy
32 *
33 * Inria,
34 * Domaine de Voluceau,
35 * 78150 Le Chesnay - Rocquencourt
36 * FRANCE
37 *
38 */
39
40#ifndef GEOGRAM_BASIC_STOPWATCH
41#define GEOGRAM_BASIC_STOPWATCH
42
46
47/****************************************************************************/
48
49#ifdef GEO_OS_WINDOWS
50#else
51#include <sys/types.h>
52#include <sys/times.h>
53#endif
54
55/****************************************************************************/
56
62namespace GEO {
63
89 class GEOGRAM_API SystemStopwatch {
90 public:
97
103 void print_elapsed_time(std::ostream& os) const;
104
110 double elapsed_user_time() const;
111
115 static double now();
116
117 private:
118#if defined(GEO_OS_WINDOWS)
119 long start_;
120#elif defined(GEO_OS_EMSCRIPTEN)
121 double startf_;
122#else
123 tms start_;
124 clock_t start_user_;
125#endif
126 };
127
128 /************************************************************************/
129
135 class GEOGRAM_API ProcessorStopwatch {
136 public:
143 start_ = now();
144 }
145
150
157 return now() - start_;
158 }
159
160 private:
161 Numeric::uint64 start_;
162 };
163
164 /************************************************************************/
165
179 class GEOGRAM_API Stopwatch {
180 public:
188 Stopwatch(const std::string& task_name, bool verbose=true) :
189 task_name_(task_name), verbose_(verbose) {
190 }
191
197 double elapsed_time() const {
198 return W_.elapsed_user_time();
199 }
200
201
208 if(verbose_) {
209 Logger::out(task_name_)
210 << "Elapsed time: " << W_.elapsed_user_time()
211 << " s" << std::endl;
212 }
213 }
214
215
216
217 private:
218 std::string task_name_;
219 bool verbose_;
221 };
222}
223
224#endif
225
Common include file, providing basic definitions. Should be included before anything else by all head...
A more precise stopwatch.
Definition stopwatch.h:135
Numeric::uint64 elapsed_time() const
Get the elapsed time.
Definition stopwatch.h:156
static Numeric::uint64 now()
ProcessorStopwatch()
ProcessorStopwatch constructor.
Definition stopwatch.h:142
Scope restricted stopwatch.
Definition stopwatch.h:179
~Stopwatch()
Stopwatch destructor.
Definition stopwatch.h:207
double elapsed_time() const
Get the user elapsed time.
Definition stopwatch.h:197
Stopwatch(const std::string &task_name, bool verbose=true)
Stopwatch constructor.
Definition stopwatch.h:188
Measures the time taken by an algorithm.
Definition stopwatch.h:89
static double now()
void print_elapsed_time(std::ostream &os) const
Prints elapsed time to a stream.
double elapsed_user_time() const
Get the user elapsed time.
SystemStopwatch()
SystemStopwatch constructor.
Generic logging mechanism.
uint64_t uint64
Definition numeric.h:99
Global Vorpaline namespace.
Definition algorithm.h:64
Types and functions for numbers manipulation.