blob: 02f180262216d7cef222e80f644ba0e8eff1aec0 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
/*
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.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()
{
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;
}
}
|