The use of the time command is very revealing when sprinkled through a procedure. It takes a very large amount of computer time to wait for a command to be loaded from the disk. Scans or build files a character at a time. Write these in C or some other compiled language. Number of Data Bytes Accessed Minimize the amount of data which must be read or written by commands in your shell procedure.
Some filters shrink their output, others increase it.
Judicious use of the cd command can help shorten search time for a file. The PATH variable should search the most often-used directory first.