mirror of
https://github.com/zebrajr/ladybird.git
synced 2025-12-06 00:19:53 +01:00
AK: Increase MonotonicTime precision on Windows
MonotonicTime was using 32 bit floats for operations on the values converted from an i64 returned by the performance counter. This caused to either precision losses or complete losses of the data for timing even things as long as hundreds of miliseconds, which should never be a problem with the resolution of the performance counter. This change fixes that behavior.
This commit is contained in:
parent
c2ca712406
commit
991ab62dd7
|
|
@ -248,17 +248,16 @@ Duration now_time_from_filetime()
|
||||||
Duration now_time_from_query_performance_counter()
|
Duration now_time_from_query_performance_counter()
|
||||||
{
|
{
|
||||||
static LARGE_INTEGER ticks_per_second;
|
static LARGE_INTEGER ticks_per_second;
|
||||||
// FIXME: Limit to microseconds for now, but could probably use nanos?
|
static f64 ticks_per_nanosecond;
|
||||||
static float ticks_per_microsecond;
|
|
||||||
if (ticks_per_second.QuadPart == 0) {
|
if (ticks_per_second.QuadPart == 0) {
|
||||||
QueryPerformanceFrequency(&ticks_per_second);
|
QueryPerformanceFrequency(&ticks_per_second);
|
||||||
VERIFY(ticks_per_second.QuadPart != 0);
|
VERIFY(ticks_per_second.QuadPart != 0);
|
||||||
ticks_per_microsecond = static_cast<float>(ticks_per_second.QuadPart) / 1'000'000.0F;
|
ticks_per_nanosecond = static_cast<f64>(ticks_per_second.QuadPart) / 1'000'000'000.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
LARGE_INTEGER now_time {};
|
LARGE_INTEGER now_time {};
|
||||||
QueryPerformanceCounter(&now_time);
|
QueryPerformanceCounter(&now_time);
|
||||||
return Duration::from_microseconds(static_cast<i64>(now_time.QuadPart / ticks_per_microsecond));
|
return Duration::from_nanoseconds(static_cast<i64>(now_time.QuadPart / ticks_per_nanosecond));
|
||||||
}
|
}
|
||||||
|
|
||||||
Duration now_time_from_clock(int clock_id)
|
Duration now_time_from_clock(int clock_id)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user