New MILLISECONDS “special” variable?

2017-11-01 Thread Alan Dipert
Hello all,

I understand there is a “special” variable, SECONDS, which returns the
number of seconds since bash invocation when referenced.

Unfortunately for tasks like profiling one’s .profile, SECONDS is too
coarse a unit. Milliseconds are more useful, but getting the time in
milliseconds is only possibly by calling out to date. (At least, I’m not
aware of a built-in way to get either Unix epoch or elapsed time in any
sub-second unit) Shelling out to date isn’t desirable as it adds
significant overhead and so complicates the task of profiling.

Would a patch adding a MILLISECONDS variable be considered? I would be
happy to work on one, if so.

I can imagine many reasons not to add a new variable, including the fact
that it could change the behavior of existing scripts. It may also be the
case that there’s already a method to get sub-second times without shelling
out, and so I’d be grateful for pointers to any existing solutions.

Thank you in advance for your thoughts, I look forward to hearing them.

Alan


Re: New MILLISECONDS “special” variable?

2017-11-03 Thread Alan Dipert
Thanks all, EPOCHREALTIME sounds perfect. I’m also glad to have learned
about loadable modules. Really cool.

Alan

On Thu, Nov 2, 2017 at 5:43 PM, Chet Ramey  wrote:

> On 11/2/17 4:09 PM, DJ Mills wrote:
> >
> >
> > On Thu, Nov 2, 2017 at 3:35 PM, Chet Ramey  > > wrote:
> >
> > There is a special builtin in the devel branch version
> (EPOCHREALTIME) that
> > gives you the epoch time with microsecond resolution. It will be in
> the
> > next release.
> >
> >
> > Out of curiosity, is that functionality going to extend to printf
> '%(fmt)T'
> > ? A %N or
> > so would be lovely
>
> It depends on what strftime(3) provides; the T format just passes what's
> between the parens to strftime().
>
> --
> ``The lyf so short, the craft so long to lerne.'' - Chaucer
>  ``Ars longa, vita brevis'' - Hippocrates
> Chet Ramey, UTech, CWRUc...@case.eduhttp://cnswww.cns.cwru.edu/~
> chet/
>