In general, one may use the
time Bash utility (see
man time for more information) to run a program, and obtain runtime duration and system resource usage summaries. But how can one time particular sections of code, directly from within the Bash source code?
This is a companion discussion topic for the original entry at https://linuxconfig.org/time-your-bash-scripts-and-procedures-from-inside-the-code