Skip to content

Commit

Permalink
benchmark (ble-measure): support an option "-V"
Browse files Browse the repository at this point in the history
  • Loading branch information
akinomyoga committed Sep 25, 2022
1 parent 2e1a7c1 commit 571ecec
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
11 changes: 6 additions & 5 deletions src/benchmark.sh
Expand Up @@ -162,6 +162,7 @@ function ble-measure/.read-arguments {
case $arg in
(--) break ;;
(--help) flags=h$flags ;;
(--no-print-progress) flags=V$flags ;;
(--*)
ble/util/print "ble-measure: unrecognized option '$arg'."
flags=E$flags ;;
Expand All @@ -170,7 +171,7 @@ function ble-measure/.read-arguments {
for ((i=1;i<${#arg};i++)); do
c=${arg:i:1}
case $c in
(q) flags=q$flags ;;
(q) flags=qV$flags ;;
([ca])
[[ $c == a ]] && flags=a$flags
ble-measure/.read-arguments.get-optarg && count=$optarg ;;
Expand Down Expand Up @@ -266,9 +267,9 @@ function ble-measure {
[[ $prev_n ]] && ((n/prev_n<=10 && prev_utot*n/prev_n<measure_threshold*2/5 && n!=50000)) && continue

local utot=0 usec=0
[[ $flags != *q* ]] && printf '%s (x%d)...' "$command" "$n" >&2
[[ $flags != *V* ]] && printf '%s (x%d)...' "$command" "$n" >&2
ble-measure/.time "$command" || return 1
[[ $flags != *q* ]] && printf '\r\e[2K' >&2
[[ $flags != *V* ]] && printf '\r\e[2K' >&2
((utot >= measure_threshold)) || continue

prev_n=$n prev_utot=$utot
Expand All @@ -278,12 +279,12 @@ function ble-measure {
if [[ $count ]]; then
local sum_utot=$utot sum_count=1 i
for ((i=2;i<=count;i++)); do
[[ $flags != *q* ]] && printf '%s' "$command (x$n $i/$count)..." >&2
[[ $flags != *V* ]] && printf '%s' "$command (x$n $i/$count)..." >&2
if ble-measure/.time "$command"; then
((utot<min_utot)) && min_utot=$utot
((sum_utot+=utot,sum_count++))
fi
[[ $flags != *q* ]] && printf '\r\e[2K' >&2
[[ $flags != *V* ]] && printf '\r\e[2K' >&2
done
if [[ $flags == *a* ]]; then
((utot=sum_utot/sum_count))
Expand Down
2 changes: 1 addition & 1 deletion src/util.sh
Expand Up @@ -3178,7 +3178,7 @@ _ble_util_msleep_calibrate_count=0
function ble/util/msleep/.calibrate-loop {
local _ble_measure_threshold=10000
local ret nsec _ble_measure_count=1 v=0
_ble_util_msleep_delay=0 ble-measure 'ble/util/msleep 1'
_ble_util_msleep_delay=0 ble-measure -q 'ble/util/msleep 1'
local delay=$((nsec/1000-1000)) count=$_ble_util_msleep_calibrate_count
((count<=0||delay<_ble_util_msleep_delay)) && _ble_util_msleep_delay=$delay # 最小値
# ((_ble_util_msleep_delay=(count*_ble_util_msleep_delay+delay)/(count+1))) # 平均値
Expand Down

0 comments on commit 571ecec

Please sign in to comment.