Enhancement: slight performance improve

atom: don't call `date` to get the timestamp multiple times in the main loop
This commit is contained in:
Vincent Riquer 2025-02-11 21:50:14 +01:00
parent 042cd72ecd
commit 0dd962fb8c

13
atom
View File

@ -708,10 +708,11 @@ echo 'BEGIN TRANSACTION;' >&3
committime=$(date +%s) committime=$(date +%s)
while (( (remaining || ${#workers[@]}) && ! quit )) while (( (remaining || ${#workers[@]}) && ! quit ))
do do
if (( $(date +%s) - committime >= 60 )) timestamp=$(date +%s)
if (( $timestamp - committime >= 60 ))
then then
echo $'COMMIT;\nBEGIN TRANSACTION;' >&3 echo $'COMMIT;\nBEGIN TRANSACTION;' >&3
committime=$(date +%s) committime=$timestamp
fi fi
read humanload garbage < /proc/loadavg read humanload garbage < /proc/loadavg
load=${humanload%.*} load=${humanload%.*}
@ -721,16 +722,16 @@ do
else else
if [ -z "$quit" ] \ if [ -z "$quit" ] \
&& (( ! pause )) \ && (( ! pause )) \
&& (( $(date +%s)-concurrencychange >= loadinterval )) && (( timestamp - concurrencychange >= loadinterval ))
then then
if (( concurrency > 1 )) \ if (( concurrency > 1 )) \
&& (( load > maxload )) && (( load > maxload ))
then then
concurrencychange=$(date +%s) concurrencychange=$timestamp
(( --concurrency )) (( --concurrency ))
elif (( load < maxload )) && (( active > concurrency - 1 )) elif (( load < maxload )) && (( active > concurrency - 1 ))
then then
concurrencychange=$(date +%s) concurrencychange=$timestamp
(( ++concurrency )) (( ++concurrency ))
fi fi
fi fi
@ -740,7 +741,7 @@ do
(( pause )) || master (( pause )) || master
if (( ran - failed )) if (( ran - failed ))
then then
currenttime=$(date +%s) currenttime=$timestamp
if (( pause )) if (( pause ))
then then
(( runtime = pausestart - starttime - pausedtime )) (( runtime = pausestart - starttime - pausedtime ))