diff options
author | mitchell <unknown> | 2018-05-06 21:22:30 -0400 |
---|---|---|
committer | mitchell <unknown> | 2018-05-06 21:22:30 -0400 |
commit | 724309f4b71d1d991a754d0ad821de3861b6a211 (patch) | |
tree | f24a11e3c550ad8ba46b92089a2ef1d3aff34663 /src/ElapsedPeriod.h | |
parent | 8971ac9fe89f01e717ad21126213ac8887fe373d (diff) | |
download | scintilla-mirror-724309f4b71d1d991a754d0ad821de3861b6a211.tar.gz |
Backport: Use <chrono> for platform-independent timing and remove ElapsedTime. Also use #if for painting measurement as there are 7 sections of code to enable.
Backport of changeset 6741:af5d9064c25c.
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 |