diff options
Diffstat (limited to 'toolsrc/include')
| -rw-r--r-- | toolsrc/include/Stopwatch.h | 40 | ||||
| -rw-r--r-- | toolsrc/include/vcpkg_Strings.h | 5 | ||||
| -rw-r--r-- | toolsrc/include/vcpkg_System.h | 2 |
3 files changed, 46 insertions, 1 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; + }; +} diff --git a/toolsrc/include/vcpkg_Strings.h b/toolsrc/include/vcpkg_Strings.h index 2aa99afe0..70526198c 100644 --- a/toolsrc/include/vcpkg_Strings.h +++ b/toolsrc/include/vcpkg_Strings.h @@ -19,6 +19,11 @@ namespace vcpkg {namespace Strings {namespace details return s; } + inline double to_printf_arg(const double s) + { + return s; + } + inline size_t to_printf_arg(const size_t s) { return s; diff --git a/toolsrc/include/vcpkg_System.h b/toolsrc/include/vcpkg_System.h index f47fc9aab..c420464c1 100644 --- a/toolsrc/include/vcpkg_System.h +++ b/toolsrc/include/vcpkg_System.h @@ -64,7 +64,7 @@ namespace vcpkg {namespace System return println(c, Strings::format(messageTemplate, messageArgs...).c_str()); } - struct Stopwatch + struct Stopwatch2 { int64_t start_time, end_time, freq; |
