1 // Scintilla source code edit control
2 /** @file ElapsedPeriod.h
3 ** Encapsulate C++ <chrono> to simplify use.
5 // Copyright 2018 by Neil Hodgson <neilh@scintilla.org>
6 // The License.txt file describes the conditions under which this software may be distributed.
8 #ifndef ELAPSEDPERIOD_H
9 #define ELAPSEDPERIOD_H
11 namespace Scintilla::Internal
{
13 // Simplified access to high precision timing.
15 using ElapsedClock
= std::chrono::steady_clock
;
16 ElapsedClock::time_point tp
;
18 /// Capture the moment
19 ElapsedPeriod() noexcept
: tp(ElapsedClock::now()) {
21 /// Return duration as floating point seconds
22 double Duration(bool reset
=false) noexcept
{
23 const ElapsedClock::time_point tpNow
= ElapsedClock::now();
24 const std::chrono::duration
<double> duration
=
25 std::chrono::duration_cast
<std::chrono::duration
<double>>(tpNow
- tp
);
29 return duration
.count();