From f4fdffef1425b7a4293a90fb96219a58b2158019 Mon Sep 17 00:00:00 2001 From: Neil Date: Thu, 26 Apr 2018 08:19:32 +1000 Subject: Use for platform-independent timing and remove ElapsedTime. Also use #if for painting measurement as there are 7 sections of code to enable. --- 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