Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Timing function execution



On Sat, Nov 6, 2021 at 11:17 AM Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> wrote:
>
> On Sat, Nov 6, 2021 at 9:21 AM Roman Perepelitsa
> <roman.perepelitsa@xxxxxxxxx> wrote:
> >
> > Could "time" invoke getrusage(RUSAGE_THREAD) before and after and
> > print the difference?
>
> That's a possibility.  It'd only work on a subset of OSs, I think.

Glancing through builtin.c, "times" (based on library times(3)) may be
the answer?

% times ; foo; times
0m0.00s 0m0.00s
0m0.00s 0m0.00s
hello
0m0.01s 0m0.00s
0m0.00s 0m0.00s

I had entirely forgotten the existence of that builtin.  Also quite
useful for a function because it separates in-shell user/system time
(first line) from sub-process (second line).




Messages sorted by: Reverse Date, Date, Thread, Author