From 3ecc67784aa9ee44953c743362023015e9a09a56 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Mon, 10 Oct 2016 18:12:26 -0700 Subject: Add Stopwatch class --- toolsrc/include/Stopwatch.h | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 toolsrc/include/Stopwatch.h (limited to 'toolsrc/include') diff --git a/toolsrc/include/Stopwatch.h b/toolsrc/include/Stopwatch.h new file mode 100644 index 000000000..2bd5c31bf --- /dev/null +++ b/toolsrc/include/Stopwatch.h @@ -0,0 +1,40 @@ +#pragma once + +#include +#include + +namespace vcpkg +{ + class Stopwatch + { + public: + static Stopwatch createUnstarted(); + + static Stopwatch createStarted(); + + bool isRunning() const; + + Stopwatch& start(); + + Stopwatch& stop(); + + Stopwatch& reset(); + + template + TimeUnit elapsed() const + { + return std::chrono::duration_cast(elapsedNanos()); + } + + std::string toString() const; + + private: + Stopwatch(); + + std::chrono::nanoseconds elapsedNanos() const; + + bool m_isRunning; + std::chrono::nanoseconds m_elapsedNanos; + std::chrono::steady_clock::time_point m_startTick; + }; +} -- cgit v1.2.3