ElapsedTimer.h 638 B

12345678910111213141516171819202122232425262728293031323334353637
  1. /*
  2. * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <AK/Time.h>
  8. namespace Core {
  9. class ElapsedTimer {
  10. public:
  11. static ElapsedTimer start_new();
  12. ElapsedTimer(bool precise = false)
  13. : m_precise(precise)
  14. {
  15. }
  16. bool is_valid() const { return m_valid; }
  17. void start();
  18. void reset();
  19. i64 elapsed() const; // milliseconds
  20. Time elapsed_time() const;
  21. Time const& origin_time() const { return m_origin_time; }
  22. private:
  23. Time m_origin_time {};
  24. bool m_precise { false };
  25. bool m_valid { false };
  26. };
  27. }