From 82a01bf32f94911de7e3d864b0c22c6cb857bf2b Mon Sep 17 00:00:00 2001 From: Andrew Kaster Date: Sun, 1 Jan 2023 13:30:09 -0700 Subject: LibJS: Use Core::ElapsedTimer in Bytecode::Pass instead of gettimeofday We have a nice utility for doing exactly what this code is using, so let's use it :^) --- Userland/Libraries/LibJS/Bytecode/PassManager.h | 26 ++++++------------------- 1 file changed, 6 insertions(+), 20 deletions(-) (limited to 'Userland') diff --git a/Userland/Libraries/LibJS/Bytecode/PassManager.h b/Userland/Libraries/LibJS/Bytecode/PassManager.h index c2f457fec5..2be204fae7 100644 --- a/Userland/Libraries/LibJS/Bytecode/PassManager.h +++ b/Userland/Libraries/LibJS/Bytecode/PassManager.h @@ -6,10 +6,9 @@ #pragma once +#include #include #include -#include -#include namespace JS::Bytecode { @@ -28,31 +27,18 @@ public: virtual void perform(PassPipelineExecutable&) = 0; void started() { - gettimeofday(&m_start_time, nullptr); + m_timer.start(); } void finished() { - struct timeval end_time { - 0, 0 - }; - gettimeofday(&end_time, nullptr); - time_t interval_s = end_time.tv_sec - m_start_time.tv_sec; - suseconds_t interval_us = end_time.tv_usec; - if (interval_us < m_start_time.tv_usec) { - interval_s -= 1; - interval_us += 1000000; - } - interval_us -= m_start_time.tv_usec; - m_time_difference = interval_s * 1000000 + interval_us; + m_time_difference = m_timer.elapsed_time(); } - u64 elapsed() const { return m_time_difference; } + u64 elapsed() const { return m_time_difference.to_microseconds(); } protected: - struct timeval m_start_time { - 0, 0 - }; - u64 m_time_difference { 0 }; + Core::ElapsedTimer m_timer; + Time m_time_difference {}; }; class PassManager : public Pass { -- cgit v1.2.3