Files
p2rank/misc/test-scripts/benchmark.sh
2016-09-27 07:55:58 +00:00

59 lines
927 B
Bash
Executable File

#!/usr/bin/env bash
#
# benchmarks a command running it repeatedly with various numbers of threads
#
REPETITIONS=$1
LABEL="$2"
THREADS="$3"
COMMAND="$4"
OUTFILE=local-speed-${LABEL}.log
DEBUG_LOG=local-debug.log
repeat() {
CMD="$@"
N=${REPETITIONS}
for (( i=1; i<=N; i++ ))
do
echo run ${i}/${N} command: \[${CMD}\]
${CMD}
done
}
benchmark() {
COM="$1"
MODIFIER="$2"
echo heat-up run 0
${COM} ${MODIFIER}
start=`date +%s`
repeat "$COM $MODIFIER"
end=`date +%s`
runtime=$((end-start))
avg_time=$((runtime/REPETITIONS))
printf "[${MODIFIER}] avg_time: %7s s\n" "$avg_time" | tee -a ${OUTFILE}
}
main() {
printf "\nbenchmarking command [$COMMAND]\n\n" > ${OUTFILE}
# iterate over thread numbers
for i in ${@}
do
benchmark "$COMMAND" "-threads $i" 2>&1 >> $DEBUG_LOG
done
cat ${OUTFILE}
}
main ${THREADS}