Things I have found helpful for script debugging and performance measurement,
in decreasing order of importance are:
1. Print debug statements in the code at suitable places.
2. Set bash debugging option -x to confirm the script is working as you intended.
3. Use the "time" command to get a general idea of where the computer is spending time.
4. Use the "gprof" and "strace" commands for performance analysis (rarely used).