diff options
author | Neil <nyamatongwe@gmail.com> | 2018-04-26 08:19:32 +1000 |
---|---|---|
committer | Neil <nyamatongwe@gmail.com> | 2018-04-26 08:19:32 +1000 |
commit | f4fdffef1425b7a4293a90fb96219a58b2158019 (patch) | |
tree | c23cc3904df927a7b9dfb1bbddcf022228f1351d /src/ElapsedPeriod.h | |
parent | 9172c913efbc014349c97740476d019690e57791 (diff) | |
download | scintilla-mirror-f4fdffef1425b7a4293a90fb96219a58b2158019.tar.gz |
Use <chrono> for platform-independent timing and remove ElapsedTime.
Also use #if for painting measurement as there are 7 sections of code to enable.
Diffstat (limited to 'src/ElapsedPeriod.h')
-rw-r--r-- | src/ElapsedPeriod.h | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/src/ElapsedPeriod.h b/src/ElapsedPeriod.h new file mode 100644 index 000000000..bbbc6d7fb --- /dev/null +++ b/src/ElapsedPeriod.h @@ -0,0 +1,35 @@ +// Scintilla source code edit control +/** @file ElapsedPeriod.h + ** Encapsulate C++ <chrono> to simplify use. + **/ +// Copyright 2018 by Neil Hodgson <neilh@scintilla.org> +// The License.txt file describes the conditions under which this software may be distributed. + +#ifndef ELAPSEDPERIOD_H +#define ELAPSEDPERIOD_H + +namespace Scintilla { + +// Simplified access to high precision timing. +class ElapsedPeriod { + std::chrono::high_resolution_clock::time_point tp; +public: + /// Capture the moment + ElapsedPeriod() : tp(std::chrono::high_resolution_clock::now()) { + } + /// Return duration as floating point seconds + double Duration(bool reset=false) { + std::chrono::high_resolution_clock::time_point tpNow = + std::chrono::high_resolution_clock::now(); + const std::chrono::duration<double> stylingDuration = + std::chrono::duration_cast<std::chrono::duration<double>>(tpNow - tp); + if (reset) { + tp = tpNow; + } + return stylingDuration.count(); + } +}; + +} + +#endif |