/* * Copyright (c) 2018-2020, Andreas Kling * * SPDX-License-Identifier: BSD-2-Clause */ #include #include #include namespace Core { ElapsedTimer ElapsedTimer::start_new() { ElapsedTimer timer; timer.start(); return timer; } void ElapsedTimer::start() { m_valid = true; m_origin_time = m_precise ? Time::now_monotonic() : Time::now_monotonic_coarse(); } void ElapsedTimer::reset() { m_valid = false; m_origin_time = {}; } i64 ElapsedTimer::elapsed() const { return elapsed_time().to_milliseconds(); } Time ElapsedTimer::elapsed_time() const { VERIFY(is_valid()); auto now = m_precise ? Time::now_monotonic() : Time::now_monotonic_coarse(); return now - m_origin_time; } }