ElapsedTimer.h 681 B

123456789101112131415161718192021222324252627282930313233343536373839
  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. static ElapsedTimer start_new();
  13. ElapsedTimer(bool precise = false)
  14. : m_precise(precise)
  15. {
  16. }
  17. bool is_valid() const { return m_valid; }
  18. void start();
  19. void reset();
  20. int elapsed() const;
  21. Time elapsed_time() const;
  22. const struct timeval& origin_time() const { return m_origin_time; }
  23. private:
  24. bool m_precise { false };
  25. bool m_valid { false };
  26. struct timeval m_origin_time {
  27. 0, 0
  28. };
  29. };
  30. }