Views:
8,558β
Votes: 3β
Tags:
bash
benchmarks
Link:
π See Original Question on Ask Ubuntu β§ π
URL:
https://askubuntu.com/q/920920
Title:
How to interpret time "real", "user" and "sys"
ID:
/2017/06/01/How-to-interpret-time-_real__-_user_-and-_sys_
Created:
June 1, 2017
Edited: June 1, 2017
Upload:
September 15, 2024
Layout: post
TOC:
false
Navigation: false
Copy to clipboard: false
Introduction
Iβve been fine-tuning code to reduce processing from 30 seconds to under a second in various parts of my bash program. Iβm having trouble wrapping my mind about how the time
command works when it reports real
, user
and sys
variables.
I have this code:
echo " "
echo "Time to build DirsNdxArr from DirsArr $DirsArrCnt elements:"
DirsArrCnt=${#DirsArr[@]}
time for (( i=1; i<$DirsArrCnt; i=i+$DaElementCnt )); do
DirsNdxArr["${DirsArr[$i]}"]=$i
AllItemSizes=$(( $AllItemSizes + ${DirsArr[$(( $i + $ColFileSizes - 1 ))]} ))
done
echo " "
echo "Time to build FilesNdxArr from FilesArr $FilesArrCnt elements:"
FilesArrCnt=${#FilesArr[@]}
time for (( i=0; i<$FilesArrCnt; i=i+$FaElementCnt )); do
FilesNdxArr["${FilesArr[$i]}"]=$i
AllTagSizes=$(( $AllTagSizes + ${FilesArr[$(( $i + $FaColFileSizes ))]} ))
done
That reports this:
Time to build DirsNdxArr from DirsArr 56700 elements:
real 0m0.149s
user 0m0.149s
sys 0m0.000s
Time to build FilesNdxArr from FilesArr 390 elements:
real 0m0.002s
user 0m0.002s
sys 0m0.000s
Why is sys
time reporting zero?
Interpreting the output of time
builtin command one would assume the system is doing nothing but surely this isnβt what is happening?
ps I know \n
can be used as a new-line to echo
with -e
parameter. My habit is to sacrifice one liner-cuteness and fringe arguments in favor of readability.