Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/sh
- : ${STRESS=10000}
- SUCCESS=0
- FAILURE=1
- f_which()
- {
- local __name="$1" __var_to_set="$2"
- case "$__name" in */*|'') return $FAILURE; esac
- if [ "$__var_to_set" ]; then
- # Do this without a sub-shell to keep things fast
- local __p IFS=":"
- for __p in $PATH; do
- local __exec="$__p/$__name"
- [ -f "$__exec" -a -x "$__exec" ] &&
- setvar "$__var_to_set" "$__exec" &&
- return $SUCCESS
- done
- else
- # Take a short-cut through the `hash' built-in
- type "$__name" > /dev/null 2>&1 &&
- hash -v "$__name" 2> /dev/null
- fi
- }
- if [ $# -ge 2 ]; then
- if [ ! "$STRESS" ]; then
- f_which "$1" "$2"
- retval=$?
- eval echo \"\$2=[\$$2]\"
- exit $retval
- else
- echo -n "Stressing f_which... "
- n=0
- start_epoch=$( date +%s )
- while [ $n -lt $STRESS ]; do
- f_which "$1" "$2"
- n=$(( $n + 1 ))
- done
- end_epoch=$( date +%s )
- echo "$(( $end_epoch - $start_epoch )) seconds ($STRESS runs)"
- echo -n "Stressing which... "
- n=0
- start_epoch=$( date +%s )
- while [ $n -lt $STRESS ]; do
- name=$( which "$1" )
- n=$(( $n + 1 ))
- done
- end_epoch=$( date +%s )
- echo "$(( $end_epoch - $start_epoch )) seconds ($STRESS runs)"
- fi
- else
- if [ ! "$STRESS" ]; then
- f_which "$1"
- exit $?
- else
- echo -n "Stressing f_which... "
- n=0
- start_epoch=$( date +%s )
- while [ $n -lt $STRESS ]; do
- f_which "$1" > /dev/null
- n=$(( $n + 1 ))
- done
- end_epoch=$( date +%s )
- echo "$(( $end_epoch - $start_epoch )) seconds ($STRESS runs)"
- echo -n "Stressing which... "
- n=0
- start_epoch=$( date +%s )
- while [ $n -lt $STRESS ]; do
- which "$1" > /dev/null
- n=$(( $n + 1 ))
- done
- end_epoch=$( date +%s )
- echo "$(( $end_epoch - $start_epoch )) seconds ($STRESS runs)"
- fi
- fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement