# vim: ft=zsh local silent=true local check=true local debug=false local i local usage=\ 'Usage: comp [-fnx] shell-code-string [shell-code-string ...] [-- number] comp -h' local help=' The shell code strings will be passed to eval, each executed number times (10 by default). If -n is given the output of the commands is NOT supressed. If -f is given the first word of the two strings is NOT checked if it is a valid command/function/alias/buildin ... With this you can compare the execution times of external commands, shell functions or literal shell code. ' while getopts fhnx FLAG; do case $FLAG in h) echo $usage; echo $help; return;; n) silent=false;; f) check=false;; # Only set xtrace if it was not set (especially only unset xtrace if we # set it ourselfs). x) [[ -o xtrace ]] || debug=true;; *) echo $usage >&2; return 2;; esac done shift $((OPTIND - 1)) cmds=() while [[ $# -ne 0 ]]; do if [[ $1 = -- ]]; then shift break fi # check that the command exists if $check; then type ${1%% *} > /dev/null 2>&1 || return 2 fi cmds+=$1 shift done count=${1:-10} ## save the current setting of shwordsplit #local oldshwordsplit= #if setopt | grep -q '^shwordsplit$'; then # oldshwordsplit=shwordsplit #else # oldshwordsplit=noshwordsplit #fi #setopt shwordsplit if $debug; then set -x fi if $silent; then exec {stdout}>&1 >/dev/null fi for ((j=1; j<=$#cmds; j++)); do printf "%d" $j time ( for i in {0..${count}} ; do ${cmds[j]} ; done ) done if $silent; then exec 1>&${stdout} {stdout}>&- fi if $debug; then set +x fi #setopt $oldshwordsplit