diff options
| author | Robert Schumacher <roschuma@microsoft.com> | 2016-10-10 23:07:29 -0700 |
|---|---|---|
| committer | Robert Schumacher <roschuma@microsoft.com> | 2016-10-10 23:07:29 -0700 |
| commit | 9e1d40e4dc313de2e6de0ac4f60a2df224215ae2 (patch) | |
| tree | bc60827a29151d7829f4b6fdeaa8d6f60e8f8258 /toolsrc/include/Stopwatch.h | |
| parent | c494892eb24ce6f84c777f24dfceb71a4988fd24 (diff) | |
| parent | 23f187a45766057ef76baba9dc912270b403cb7d (diff) | |
| download | vcpkg-9e1d40e4dc313de2e6de0ac4f60a2df224215ae2.tar.gz vcpkg-9e1d40e4dc313de2e6de0ac4f60a2df224215ae2.zip | |
Merge branch 'master' of https://github.com/microsoft/vcpkg
Diffstat (limited to 'toolsrc/include/Stopwatch.h')
| -rw-r--r-- | toolsrc/include/Stopwatch.h | 40 |
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; + }; +} |
