1
0
Fork 0
mirror of git://git.code.sf.net/p/zsh/code synced 2025-10-27 16:50:58 +01:00

53257: use monotonic clock where appropriate

update the following features to use the monotonic clock for calculating time
deltas and intervals:

* MAILCHECK parameter
* PERIOD parameter
* SECONDS parameter
* %(nS.t.f) prompt-expansion sequence
* time built-in's elapsed time and cpu % values
* zsh/zftp ZFTP_TMOUT parameter
* zsh/zprof timings

also use CLOCK_MONOTONIC_RAW instead of CLOCK_MONOTONIC on macOS
This commit is contained in:
dana 2024-12-26 09:36:45 -06:00
parent 7798fd88ac
commit 6bb792dba8
18 changed files with 225 additions and 92 deletions

View file

@ -11,9 +11,44 @@
(time cat) >&/dev/null
0:`time' keyword (status only)
( TIMEFMT='%E %mE %uE %* %m%mm %u%uu'; time (:) )
( TIMEFMT='%E %mE %uE %nE %* %m%mm %u%uu %n%nn'; time (:) )
0:`time' keyword with custom TIMEFMT
*?[0-9]##.[0-9](#c2)s [0-9]##ms [0-9]##us %\* %m%mm %u%uu
*?[0-9]##.[0-9](#c2)s [0-9]##ms [0-9]##us [0-9]##ns %\* %m%mm %u%uu %n%nn
( TIMEFMT='x %U %S %E'; time (:) )
0:TIMEFMT %[USE] use centisecond precision
*?x( <0-9>.<00-99>s)(#c3)
( TIMEFMT='x %*U %*S %*E'; time (:) )
0:TIMEFMT %*[USE] use millisecond precision
*?x( <0-9>.<000-999>)(#c3)
( TIMEFMT='%nU %nS'; time (read -k3 -t0.1) )
1:TIMEFMT %nU and %nS are limited to microsecond precision
*?[1-9][0-9]#000ns [1-9][0-9]#000ns
# SECONDS (after - before) must be greater than the elapsed time, but not much
# greater. 25% was picked arbitrarily as something that hopefully will prevent
# the test from failing on slow machines
(
typeset -F SECONDS
TIMEFMT=%nE
a=$SECONDS
t=$( (time (read -k3 -t0.1)) 2>&1 )
b=$SECONDS
s=$(( b - a ))
t=$(( ${t%ns}.0 / 10**9 ))
echo $s $t $(( s > t )) $(( t > s - (s * 0.25) ))
)
0:`time' elapsed time matches SECONDS
*>[0-9.]## [0-9.]## 1 1
# Again, the wide range here is an attempt to prevent this test from failing on
# slow machines. We don't care about the exact time, just that it's vaguely sane
# and that each representation has the same basis
( TIMEFMT='%E %mE %uE %nE %*E'; time (read -k3 -t0.1) )
1:TIMEFMT elapsed time values
*?0.<10-50>s <10-500>ms <100000-500000>us <100000000-500000000>ns 0.<100-500>
time x=1
0:`time' simple assignment

View file

@ -68,6 +68,13 @@
print -P '%(?.true.false)'
0:ternary prompt escapes
>true
>false
sec=$SECONDS
eval "print -P '%(${sec}S.true.false)'"
eval "print -P '%($((sec+30))S.true.false)'"
0:ternary prompt escape with test character S
>true
>false
print -P 'start %10<...<truncated at 10%<< Not truncated%3< ...<Not shown'

View file

@ -1550,6 +1550,28 @@
>1
>1
# Integer
a=$SECONDS
sleep 1
b=$SECONDS
print -r - $a $b $(( b > a ))
# Float
typeset -F SECONDS
a=$SECONDS
repeat 10 :
b=$SECONDS
print -r - $a $b $(( b > a ))
# Assignment
a=$SECONDS
SECONDS=8888
repeat 10 :
b=$SECONDS
print -r - $(( a < 8888 )) $(( b > 8888 ))
0:SECONDS
*>[0-9]## [0-9]## 1
*>[0-9]##.[0-9]## [0-9]##.[0-9]## 1
*>1 1
foo=("|" "?")
[[ "|" = ${(j.|.)foo} ]] && print yes || print no
[[ "|" = ${(j.|.)~foo} ]] && print yes || print no