Blue Brain BioExplorer
Timer.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2017-2024, EPFL/Blue Brain Project
3  *
4  * This file is part of Blue Brain BioExplorer <https://github.com/BlueBrain/BioExplorer>
5  *
6  * This library is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU Lesser General Public License version 3.0 as published
8  * by the Free Software Foundation.
9  *
10  * This library is distributed in the hope that it will be useful, but WITHOUT
11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12  * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
13  * details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with this library; if not, write to the Free Software Foundation, Inc.,
17  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18  */
19 
20 #pragma once
21 
22 #include <chrono>
23 
24 namespace core
25 {
26 using clock = std::chrono::high_resolution_clock;
27 
29 class Timer
30 {
31 public:
32  Timer();
33 
35  void start();
36 
38  void stop();
39 
41  double elapsed() const;
42 
44  int64_t microseconds() const;
45 
47  int64_t milliseconds() const;
48 
50  double seconds() const;
51 
56  double perSecond() const;
57 
61  double fps() const;
62 
67  double perSecondSmoothed() const;
68 
69 private:
70  clock::time_point _startTime;
71  int64_t _microseconds{0};
72  double _smoothNom{0.0};
73  double _smoothDen{0.0};
74  const double _smoothingFactor{0.9}; // closer to 1 means more smoothing
75  clock::time_point _lastFPSTickTime;
76  double _fps{0.0};
77 };
78 } // namespace core
double perSecond() const
Definition: Timer.cpp:75
int64_t microseconds() const
Definition: Timer.cpp:60
double perSecondSmoothed() const
Definition: Timer.cpp:80
void start()
Definition: Timer.cpp:34
void stop()
Definition: Timer.cpp:44
double seconds() const
Definition: Timer.cpp:70
double fps() const
Definition: Timer.cpp:85
int64_t milliseconds() const
Definition: Timer.cpp:65
double elapsed() const
Definition: Timer.cpp:39
std::chrono::high_resolution_clock clock
Definition: Timer.h:26