Easy3D 2.5.3
stop_watch.h
1/********************************************************************
2 * Copyright (C) 2015 Liangliang Nan <liangliang.nan@gmail.com>
3 * https://3d.bk.tudelft.nl/liangliang/
4 *
5 * This file is part of Easy3D. If it is useful in your research/work,
6 * I would be grateful if you show your appreciation by citing it:
7 * ------------------------------------------------------------------
8 * Liangliang Nan.
9 * Easy3D: a lightweight, easy-to-use, and efficient C++ library
10 * for processing and rendering 3D data.
11 * Journal of Open Source Software, 6(64), 3255, 2021.
12 * ------------------------------------------------------------------
13 *
14 * Easy3D is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License Version 3
16 * as published by the Free Software Foundation.
17 *
18 * Easy3D is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
22 *
23 * You should have received a copy of the GNU General Public License
24 * along with this program. If not, see <http://www.gnu.org/licenses/>.
25 ********************************************************************/
26
27#ifndef EASY3D_UTIL_STOP_WATCH_H
28#define EASY3D_UTIL_STOP_WATCH_H
29
30#include <string>
31
32#ifdef _WIN32
33#include <cstdint>
34#else
35#include <ctime>
36#endif // _WIN32
37
38
39namespace easy3d {
40
55 class StopWatch {
56 public:
58 StopWatch();
60 ~StopWatch() = default;
61
63 void start();
65 void restart();
66
68 double elapsed_seconds(int num_digits = 1) const;
69
71 std::string time_string(int num_digits = 1) const;
72
73 private:
74 double seconds() const;
75
76#ifdef _WIN32
77 int64_t freq_;
78 int64_t start_count_;
79#else
80 timeval start_time_;
81#endif
82
83 };
84
85} // namespace easy3d
86
87
88#endif // EASY3D_UTIL_STOP_WATCH_H
89
A high resolution stop watch/timer.
Definition: stop_watch.h:55
void restart()
restarts the timer. It has the same effect as start()
Definition: stop_watch.cpp:62
~StopWatch()=default
destructor.
void start()
starts the timer
Definition: stop_watch.cpp:49
double elapsed_seconds(int num_digits=1) const
returns user elapsed time (in seconds) since the construction / start.
Definition: stop_watch.cpp:81
StopWatch()
default constructor. The watch will automatically start after construction.
Definition: stop_watch.cpp:44
std::string time_string(int num_digits=1) const
the elapsed time string, e.g., 88ms, 2.3s, 1.7m, 0.1h. This function automatically determines the bes...
Definition: stop_watch.cpp:86
Definition: collider.cpp:182