From 724309f4b71d1d991a754d0ad821de3861b6a211 Mon Sep 17 00:00:00 2001 From: mitchell Date: Sun, 6 May 2018 21:22:30 -0400 Subject: Backport: Use 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. --- src/ElapsedPeriod.h | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 src/ElapsedPeriod.h (limited to 'src/ElapsedPeriod.h') 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++ to simplify use. + **/ +// Copyright 2018 by Neil Hodgson +// 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 stylingDuration = + std::chrono::duration_cast>(tpNow - tp); + if (reset) { + tp = tpNow; + } + return stylingDuration.count(); + } +}; + +} + +#endif -- cgit v1.2.3