File: Timer.h

package info (click to toggle)
jazz2-native 3.5.0-2
  • links: PTS, VCS
  • area: contrib
  • in suites: forky, sid
  • size: 16,912 kB
  • sloc: cpp: 172,557; xml: 113; python: 36; makefile: 5; sh: 2
file content (38 lines) | stat: -rw-r--r-- 780 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#pragma once

#include <cstdint>

namespace nCine
{
	/// Accumulates the time between starting and stopping the time measurement
	class Timer
	{
	public:
		Timer();

		/// Starts the timer
		void start();
		/// Stops the timer
		void stop();
		/// Resets the accumulated time
		inline void reset() {
			_accumulatedTime = 0ULL;
		}
		/// Returns `true` if the timer is running
		inline bool isRunning() const {
			return _isRunning;
		}

		/// Returns elapsed time in seconds since last starting the timer
		float interval() const;
		/// Returns total accumulated time in seconds
		float total() const;

	private:
		bool _isRunning;
		/// Start time mark
		std::uint64_t _startTime;
		/// Accumulated time ticks over multiple start and stop
		std::uint64_t _accumulatedTime;
	};
}