[flang-commits] [flang] [Flang][runtime] Distinguish CPU time and elapsed time for cpu_time and system_clock (PR #96652)
Kareem Ergawy via flang-commits
flang-commits at lists.llvm.org
Thu Jun 27 02:42:53 PDT 2024
================
@@ -0,0 +1,27 @@
+! RUN: %flang -o %t %s
+! RUN: %t
+
+program system_clock_test
+ use iso_fortran_env, only: int64, real64
+ implicit none
+
+ integer, parameter :: delta = 1
+ real(kind=real64), parameter :: epsilon = 0.001
+
+ integer(kind=int64) :: t_start, t_end
+ integer(kind=int64) :: rate
+ real(kind=real64) :: diff
+
+ call system_clock(count_rate=rate)
+
+ call system_clock(t_start)
+ call sleep(delta)
+ call system_clock(t_end)
+
+ diff = real(t_end - t_start, kind=real64) / real(rate, kind=real64)
+
+ if (abs(diff - real(delta, kind=real64)) <= epsilon) then
----------------
ergawy wrote:
Isn't that check flakey? `delta` is the minimum amount of time the thread will sleep but there is not guranatee the actual sleep will be longer than that if the CPU is busy, right? Or did I miss something?
https://github.com/llvm/llvm-project/pull/96652
More information about the flang-commits
mailing list