ElapsedTimer.h 625 B

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