mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 07:30:19 +00:00
43 lines
881 B
C++
43 lines
881 B
C++
/*
|
|
* Copyright (c) 2018-2020, Andreas Kling <andreas@ladybird.org>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#include <AK/Assertions.h>
|
|
#include <AK/Time.h>
|
|
#include <LibCore/ElapsedTimer.h>
|
|
|
|
namespace Core {
|
|
|
|
ElapsedTimer ElapsedTimer::start_new(TimerType timer_type)
|
|
{
|
|
ElapsedTimer timer(timer_type);
|
|
timer.start();
|
|
return timer;
|
|
}
|
|
|
|
void ElapsedTimer::start()
|
|
{
|
|
m_valid = true;
|
|
m_origin_time = m_timer_type == TimerType::Precise ? MonotonicTime::now() : MonotonicTime::now_coarse();
|
|
}
|
|
|
|
void ElapsedTimer::reset()
|
|
{
|
|
m_valid = false;
|
|
}
|
|
|
|
i64 ElapsedTimer::elapsed_milliseconds() const
|
|
{
|
|
return elapsed_time().to_milliseconds();
|
|
}
|
|
|
|
AK::Duration ElapsedTimer::elapsed_time() const
|
|
{
|
|
VERIFY(is_valid());
|
|
auto now = m_timer_type == TimerType::Precise ? MonotonicTime::now() : MonotonicTime::now_coarse();
|
|
return now - m_origin_time;
|
|
}
|
|
|
|
}
|