1 // Scintilla source code edit control
2 /** @file ElapsedPeriod.h
3  ** Encapsulate C++ <chrono> to simplify use.
4  **/
5 // Copyright 2018 by Neil Hodgson <neilh@scintilla.org>
6 // The License.txt file describes the conditions under which this software may be distributed.
7 
8 #ifndef ELAPSEDPERIOD_H
9 #define ELAPSEDPERIOD_H
10 
11 namespace Scintilla {
12 
13 // Simplified access to high precision timing.
14 class ElapsedPeriod {
15 	std::chrono::high_resolution_clock::time_point tp;
16 public:
17 	/// Capture the moment
ElapsedPeriod()18 	ElapsedPeriod() noexcept : tp(std::chrono::high_resolution_clock::now()) {
19 	}
20 	/// Return duration as floating point seconds
21 	double Duration(bool reset=false) noexcept {
22 		const std::chrono::high_resolution_clock::time_point tpNow =
23 			std::chrono::high_resolution_clock::now();
24 		const std::chrono::duration<double> stylingDuration =
25 			std::chrono::duration_cast<std::chrono::duration<double>>(tpNow - tp);
26 		if (reset) {
27 			tp = tpNow;
28 		}
29 		return stylingDuration.count();
30 	}
31 };
32 
33 }
34 
35 #endif
36