help-bash
[Top][All Lists]
Advanced

[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 02:08:01 +0000

‐‐‐‐‐‐‐ Original Message ‐‐‐‐‐‐‐
On Thursday, August 19, 2021 2:01 AM, Seth David Schoen <schoen@loyalty.org> 
wrote:

> hancooper via writes:
>
> > How can I use two time stamps and compute the elapsed time?
> > I have a search command that I want to also compute the execution time
>
> Well, bash's built-in arithmetic only acts on integers, so if the time
> stamps have a decimal part or you want precision less than one second,
> you can't directly do it natively in pure bash.
>
> If you want precision only accurate to a whole second, you can use
> $(($B-$A)), like
>
> $ B=1245
> $ A=1240
> $ echo $(($B-$A))
> 5
>
> But this won't work if there is a decimal point in either number. In
> that case, you might want to pipe into bc, like
>
> $ B=1245.12983
> $ A=1240.91289
> $ echo "$B-$A" | bc
> 4.21694
>
> This is slower because it creates a subprocess to perform the arithmetic
> calculation.

What command would one use to set A and B ?



reply via email to

[Prev in Thread] Current Thread [Next in Thread]