Basic-benchmark-experiment/www/scripts/time-aggregation-progress.sh

30 lines
1.2 KiB
Bash

#!/bin/bash
benchmark() {
total_real_time=0
total_user_time=0
total_system_time=0
for ((i=0; i<$1; i++)); do
printf "\r%04d/%04d %s" $i $1 "$2" >&2
time_slept=($( (TIMEFORMAT="%R %U %S"; time $2 1>/dev/null) |& tr -d . ))
#echo -e "${time_slept[@]}\n"
#((total_real_time+=$(echo ${time_slept[0]} | sed 's/^0*(?=[0-9])//;s/^0/0/')))
((total_real_time+=$(printf '%d' $(echo ${time_slept[0]} | sed 's/^0*//'))))
#((total_user_time+=$(echo ${time_slept[1]} | sed 's/^0*(?=[0-9])//;s/^0/0/')))
((total_user_time+=$(printf '%d' $(echo ${time_slept[1]} | sed 's/^0*//'))))
#((total_system_time+=$(echo ${time_slept[2]} | sed 's/^0*(?=[0-9])//;s/^0/0/')))
((total_system_time+=$(printf '%d' $(echo ${time_slept[2]} | sed 's/^0*//'))))
done
printf "\n" >&2
echo "Total real time: ${total_real_time}ms; Average real time: $(bc <<< "scale=3; $total_real_time / $1")ms"
echo "Total user time: ${total_user_time}ms; Average user time: $(bc <<< "scale=3; $total_user_time / $1")ms"
echo "Total system time: ${total_system_time}ms; Average system time: $(bc <<< "scale=3; $total_system_time / $1")ms"
}
# benchmark 3 'sleep 1s'
#benchmark 3 'python3 ../../Python/code_cycle.py'