aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/ElapsedPeriod.h
diff options
context:
space:
mode:
authormitchell <unknown>2018-05-06 21:22:30 -0400
committermitchell <unknown>2018-05-06 21:22:30 -0400
commit724309f4b71d1d991a754d0ad821de3861b6a211 (patch)
treef24a11e3c550ad8ba46b92089a2ef1d3aff34663 /src/ElapsedPeriod.h
parent8971ac9fe89f01e717ad21126213ac8887fe373d (diff)
downloadscintilla-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.h35
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