ElapsedTimer.h 573 B

12345678910111213141516171819202122232425262728293031323334
  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 <sys/time.h>
  8. namespace Core {
  9. class ElapsedTimer {
  10. public:
  11. ElapsedTimer(bool precise = false)
  12. : m_precise(precise)
  13. {
  14. }
  15. bool is_valid() const { return m_valid; }
  16. void start();
  17. int elapsed() const;
  18. const struct timeval& origin_time() const { return m_origin_time; }
  19. private:
  20. bool m_precise { false };
  21. bool m_valid { false };
  22. struct timeval m_origin_time {
  23. 0, 0
  24. };
  25. };
  26. }