Skip to content

Commit

Permalink
benchmark (ble-measure): work around the locale for "EPOCHREALTIME"
Browse files Browse the repository at this point in the history
  • Loading branch information
akinomyoga committed May 19, 2021
1 parent 1d48e79 commit f3833ad
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
5 changes: 4 additions & 1 deletion src/util.sh
Expand Up @@ -2271,17 +2271,20 @@ _ble_util_clock_base=
_ble_util_clock_reso=
_ble_util_clock_type=
function ble/util/clock/.initialize {
local LC_ALL= LC_NUMERIC=C
if ((_ble_bash>=50000)) && [[ $EPOCHREALTIME == *.???* ]]; then
# implementation with EPOCHREALTIME
_ble_util_clock_base=$((10#${EPOCHREALTIME%.*}))
_ble_util_clock_reso=1
_ble_util_clock_type=EPOCHREALTIME
function ble/util/clock {
local LC_ALL= LC_NUMERIC=C
local now=$EPOCHREALTIME
local integral=$((10#${now%%.*}-_ble_util_clock_base))
local mantissa=${now#*.}000; mantissa=${mantissa::3}
((ret=integral*1000+10#$mantissa))
}
ble/function#suppress-stderr ble/util/clock # locale
elif [[ -r /proc/uptime ]] && {
local uptime
ble/util/readfile uptime /proc/uptime
Expand Down Expand Up @@ -2317,7 +2320,7 @@ function ble/util/clock/.initialize {
}
fi
}
ble/util/clock/.initialize
ble/util/clock/.initialize 2>/dev/null

if ((_ble_bash>=40000)); then
## 設定関数 ble/util/idle/IS_IDLE { ble/util/is-stdin-ready; }
Expand Down
9 changes: 7 additions & 2 deletions test/benchmark/benchmark.sh
Expand Up @@ -41,11 +41,16 @@ if [[ $ZSH_VERSION ]]; then
}
elif ((BASH_VERSINFO[0]>=5)); then
_ble_measure_resolution=1 # [usec]
function ble-measure/.get-realtime {
local LC_ALL= LC_NUMERIC=C
time=$EPOCHREALTIME
}
function ble-measure/.time {
local command="$*"
local time1=${EPOCHREALTIME//.}
local time
ble-measure/.get-realtime 2>/dev/null; local time1=${time//.}
ble-measure/.loop "$n" "$*" &>/dev/null
local time2=${EPOCHREALTIME//.}
ble-measure/.get-realtime 2>/dev/null; local time2=${time//.}
((utot=time2-time1,usec=utot/n))
((utot>0))
}
Expand Down

0 comments on commit f3833ad

Please sign in to comment.