From ee765e241ec8338b4a6e3c44e5864a2bce630e5d Mon Sep 17 00:00:00 2001 From: Tim Ledbetter Date: Mon, 26 Feb 2024 17:52:03 +0000 Subject: [PATCH] LibWeb: Allow performance timestamps to have sub-millisecond precision Rather than returning the number of whole elapsed milliseconds, we now return the number of elapsed nanoseconds divided by one million. This allows us to make use of the fractional part of the double that is returned. --- Userland/Libraries/LibWeb/HighResolutionTime/Performance.cpp | 2 +- Userland/Libraries/LibWeb/HighResolutionTime/Performance.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Userland/Libraries/LibWeb/HighResolutionTime/Performance.cpp b/Userland/Libraries/LibWeb/HighResolutionTime/Performance.cpp index 865300f0d2..f11cbd8ef1 100644 --- a/Userland/Libraries/LibWeb/HighResolutionTime/Performance.cpp +++ b/Userland/Libraries/LibWeb/HighResolutionTime/Performance.cpp @@ -52,7 +52,7 @@ JS::GCPtr Performance::timing() double Performance::time_origin() const { - return static_cast(m_timer.origin_time().milliseconds()); + return static_cast(m_timer.origin_time().nanoseconds()) / 1e6; } // https://w3c.github.io/user-timing/#mark-method diff --git a/Userland/Libraries/LibWeb/HighResolutionTime/Performance.h b/Userland/Libraries/LibWeb/HighResolutionTime/Performance.h index cdda943ae8..213dbeeef3 100644 --- a/Userland/Libraries/LibWeb/HighResolutionTime/Performance.h +++ b/Userland/Libraries/LibWeb/HighResolutionTime/Performance.h @@ -21,7 +21,7 @@ class Performance final : public DOM::EventTarget { public: virtual ~Performance() override; - double now() const { return static_cast(m_timer.elapsed()); } + double now() const { return static_cast(m_timer.elapsed_time().to_nanoseconds()) / 1e6; } double time_origin() const; JS::GCPtr timing();