For comparing run times of scripts between different shells, some SE answers suggest using
time command, like so:
time bash -c 'foo.sh' time dash -c 'foo.sh'
...etc, for every shell to test. Such benchmarks fail to eliminate the time taken for each shell to load and initialize itself. For example, suppose both of the above commands were stored on a slow device with the read speed of an early floppy disk, (124KB/s),
dash (a ~150K executable) would load about 7x faster than
bash (~1M), the shell loading time would skew the
time numbers -- the pre-loading times of those shells being irrelevant to measuring the run times of
foo.sh under each shell after the shells were loaded.
What's the best portable and general util to run for script timing that can be run from within each shell? So the above code would look something like:
bash -c 'general_timer_util foo.sh' dash -c 'general_timer_util foo.sh'
NB: no shell built-in
time commands, since none are portable or general.
Better yet if the util is also able to benchmark the time taken by a shell's internal commands and pipelines, without the user having to first wrap them in a script. Artificial syntax like this would help:
general_timer_util "while read x ; do echo x ; done < foo"
time can manage this. For example
bash -c "time while false ; do : ; done" works. To see what works, (and doesn't), on your system try:
tail +2 /etc/shells | while read s ; do echo $s ; $s -c "time while false ; do : ; done" ; echo ---- done