[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Duration between two time stamps
From: |
hancooper |
Subject: |
Duration between two time stamps |
Date: |
Thu, 19 Aug 2021 11:14:25 +0000 |
‐‐‐‐‐‐‐ Original Message ‐‐‐‐‐‐‐
On Thursday, August 19, 2021 5:10 AM, Tapani Tarvainen
<bash@tapanitarvainen.fi> wrote:
> On Thu, Aug 19, 2021 at 11:23:22AM +0900, Koichi Murase
> (myoga.murase@gmail.com) wrote:
>
> > In Bash 5.0+, you may use the special shell variables, EPOCHSECONDS
> > (for granularity of seconds) or EPOCHREALTIME (for finer granularity).
> > A=$EPOCHREALTIME
> > your_search_command
> > B=$EPOCHREALTIME
>
> Yes. And it's worth noting that $EPOCHREALTIME does not drop
> trailing zeroes, there're always six digits after the decimal point.
>
> So if you're happy with the difference in microseconds, you can
> simply discard the decimal points and subtract the resulting
> microsecond values:
>
> echo $((${B/.}-${A/.}))
>
> If you want it in seconds but don't want to spawn bc or the like, you
> can add the decimal point back, e.g., like this:
>
> udiff1=$((${B/.}-${A/.}+1000000))
> sec1=${udiff1::-6}
> echo $((sec1-1)).${udiff1#$sec1}
>
> An extra second is added and later substracted to deal with leading
> zeroes in case the time difference is less than a second.
>
> Incidentally, why does ${var:offset} with a negative offset result in
> an empty string when the variable is shorter than the offset? E.g.,
>
> x=abc
> echo ${x: -6}
>
> I find that counterintuitive, and it'd actually be useful to
> be able to get "at most N characters from the end".
Am not getting output from $EPOCHREALTIME
A=$EPOCHREALTIME
grep --null -r -l "${isufx[@]}" -e "$ptrn" -- "${fdir[@]}" |
sed -z "${sta}~${stp}!d" |
PARALLEL_SHELL=bash psgc=$sgc psgr=$sgr ptn=$ptrn \
parallel -m0kj"$procs" \
'for fl in {}; do
printf "\n%s\n\n" "$psgc==> $fl <==$psgr"
grep --color=always -ni '"${ictx[@]@Q}"' -e "$ptn" -- "$fl"
done'
B=$EPOCHREALTIME
DT=$( ${B}-${A} | bc )
printf '\n%s\n' "A:$A | B:$B | DT: $DT"
As I had GNU bash, version 4.4, I have just installed
GNU bash, version 5.1.8(1)-release (x86_64-pc-linux-gnu)
- Duration between two time stamps, hancooper, 2021/08/18
- Re: Duration between two time stamps, Seth David Schoen, 2021/08/18
- Duration between two time stamps, hancooper, 2021/08/18
- Re: Duration between two time stamps, Seth David Schoen, 2021/08/18
- Re: Duration between two time stamps, Koichi Murase, 2021/08/18
- Re: Duration between two time stamps, Tapani Tarvainen, 2021/08/19
- Duration between two time stamps,
hancooper <=
- Re: Duration between two time stamps, Alex fxmbsw7 Ratchev, 2021/08/19
- Duration between two time stamps, hancooper, 2021/08/19
- Re: Duration between two time stamps, Koichi Murase, 2021/08/19
- Duration between two time stamps, hancooper, 2021/08/19
- Re: Duration between two time stamps, Alex fxmbsw7 Ratchev, 2021/08/19
- Re: Duration between two time stamps, Greg Wooledge, 2021/08/19
- Duration between two time stamps, hancooper, 2021/08/19
- Re: Duration between two time stamps, Koichi Murase, 2021/08/19
- Re: Duration between two time stamps, Koichi Murase, 2021/08/19
- Re: Duration between two time stamps, Tapani Tarvainen, 2021/08/20