timer.h 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. // Copyright 2013 Dolphin Emulator Project / 2014 Citra Emulator Project
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #pragma once
  5. #include <chrono>
  6. #include <string>
  7. #include "common/common_types.h"
  8. namespace Common {
  9. class Timer {
  10. public:
  11. Timer();
  12. void Start();
  13. void Stop();
  14. void Update();
  15. // The time difference is always returned in milliseconds, regardless of alternative internal
  16. // representation
  17. [[nodiscard]] std::chrono::milliseconds GetTimeDifference();
  18. void AddTimeDifference();
  19. [[nodiscard]] static std::chrono::seconds GetTimeSinceJan1970();
  20. [[nodiscard]] static std::chrono::seconds GetLocalTimeSinceJan1970();
  21. [[nodiscard]] static double GetDoubleTime();
  22. [[nodiscard]] static std::string GetTimeFormatted();
  23. [[nodiscard]] std::string GetTimeElapsedFormatted() const;
  24. [[nodiscard]] std::chrono::milliseconds GetTimeElapsed();
  25. [[nodiscard]] static std::chrono::milliseconds GetTimeMs();
  26. private:
  27. std::chrono::milliseconds m_LastTime;
  28. std::chrono::milliseconds m_StartTime;
  29. bool m_Running;
  30. };
  31. } // Namespace Common