Work out bash script runtime instantly with clear inputs, formula shown and shareable results.
Shell script performance is dominated by process creation, not by shell logic. A fork and exec costs around a millisecond while a builtin costs microseconds, so three external commands per iteration over 100,000 iterations spends six minutes forking. Replacing calls to cut, grep and sed with parameter expansion or a single awk invocation is where the gains are.
Script runtime
fork time = iterations x subprocesses x fork cost; builtin time = iterations x builtin cost; total = both
Anything called inside a loop: basename, dirname, cut, expr, wc and seq all have builtin equivalents using parameter expansion or arithmetic.
Once it processes tens of thousands of records or needs data structures. Python or awk will run one to two orders of magnitude faster and be easier to maintain.