Hi deetee
Thank you very much for your work. To analyze in detail and improve my program sustainable (in this short time) indicates that you are a "professional scripter" - thanks to learn from you.
You are quite welcome, however, "professional" is too strong a word. Amateur would be more than generous.
Unfortunately, if the number of files in a directory is less and the keys are pressed fast, some "residual" parts ...
Yes, those are two different issues. One is caused by changing into a directory containing less than a panel full of
entries AND less entries then the previous directory. That case is handled by clearing the panel when changing
directories. The other is caused by not being able to process the keyboard fast enough, and that is what you need to address.
On my machine, from the time you hit the UP or DOWN arrow key, to the time your program hits the next call to _get_key
takes about 0.22 seconds. About 0.08 seconds are spent in _print_bar and another 0.08 seconds in _print_status. In my
opinion, you are making far too many ls calls, and it is one of the things hurting the execution speed. I would begin by
looking at _print_status. There is no need to calculate directory size and disk space used unless someone copies, deletes,
or moves a file. Make those values global, and only recalculate them when one of your routines does something to change
them. Also, the size of the disk never changes, place that into a global when the program starts. Since those values are
printed one after the other in your status bar, you can then simply:
echo -n "/$DIRSIZE $DISKUSED/$DISKSIZE "
By including a trailing space, you don't have to make an extra echo call prior to printing the time. This section:
echo -n " " # permission
echo -n $( (ls -lA $PATH0 | grep "^d" ; ls -lA $PATH0 | grep "^-") |
awk '{ print $1;}' | head -$FILECHOOSE | tail -1)
consumes 0.03 seconds of _print_status. You could reduce that to about 0.01 seconds like this:
echo -n $(ls -lA $PATH0 | grep $CHOSENFILE | cut -d" " -f1)
Here is how I did the timing measurements, modify main like this:
echo $CUROFF
Time1=`cat /proc/uptime | cut -d" " -f1`
while :
do
_print
Time2=`cat /proc/uptime | cut -d" " -f1`
echo -n "${CSI}$(($STATUSLINE + 2));1H`dc $Time2 $Time1 sub p`$CLEARSTRING"
echo -n "${CSI}$(($STATUSLINE + 3));1H`dc $Time4 $Time3 sub p`$CLEARSTRING"
_get_key
Time1=`cat /proc/uptime | cut -d" " -f1`
The first echo statement times from when you hit a key until you are ready to process the next key. The secon echo
statement is for timing other sections of the script using Time3 and Time4 like this:
_print(){ # print actual pan and status
_print_path
if [ $PAN -eq 1 ]; then _print_pan1
else _print_pan2; fi
_print_bar
Time3=`cat /proc/uptime | cut -d" " -f1`
_print_status
Time4=`cat /proc/uptime | cut -d" " -f1`
}
Here I'm measuring the execution time of _print_status. Timing resolution is 0.01 seconds. Always make several
measurements to check for consistent results. This post is rather long, so I'll end it by quoting my previous post:
The key to fast program execution is to make the computer do as little work as possible.