aboutsummaryrefslogtreecommitdiff
path: root/toolsrc/include
diff options
context:
space:
mode:
Diffstat (limited to 'toolsrc/include')
-rw-r--r--toolsrc/include/Stopwatch.h40
1 files changed, 40 insertions, 0 deletions
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 <chrono>
+#include <string>
+
+namespace vcpkg
+{
+ class Stopwatch
+ {
+ public:
+ static Stopwatch createUnstarted();
+
+ static Stopwatch createStarted();
+
+ bool isRunning() const;
+
+ Stopwatch& start();
+
+ Stopwatch& stop();
+
+ Stopwatch& reset();
+
+ template <class TimeUnit>
+ TimeUnit elapsed() const
+ {
+ return std::chrono::duration_cast<TimeUnit>(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;
+ };
+}