Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: time command with shell builtins
- X-seq: zsh-users 28757
- From: Dominik Vogt <dominik.vogt@xxxxxx>
- To: Zsh Users <zsh-users@xxxxxxx>
- Subject: Re: time command with shell builtins
- Date: Mon, 23 Jan 2023 19:49:23 +0100
- Archived-at: <https://zsh.org/users/28757>
- In-reply-to: <CAHYJk3QD8NbCqt0LdXshiVf6W3GQLnDzo6-1mj0qCJOTkHFGRA@mail.gmail.com>
- List-id: <zsh-users.zsh.org>
- Mail-followup-to: Zsh Users <zsh-users@xxxxxxx>
- References: <Y86OR0DCpwfSYCXU@localhost> <CAN=4vMqSxEr-K1xg+fGc9kh2qfiZ31fy7hoDBRNHXXF6pH8eEg@mail.gmail.com> <Y86ZkYooJ9Kf4xCE@localhost> <CAHYJk3QD8NbCqt0LdXshiVf6W3GQLnDzo6-1mj0qCJOTkHFGRA@mail.gmail.com>
- Reply-to: dominik.vogt@xxxxxx
- Ui-outboundreport: notjunk:1;M01:P0:Rg1hy9npVzs=;fJbDBy/uR9HkqbOAPnji8L5Jc31 tWTCt3oM3jFMcn8x1ak6jmj5ryVBYCz9wweYoWfucbcefpeugbRoDKJBv4V5VjfEoW1ZLCHM0 0bkiglBOgpbTrVeHcPVko6el8Z5C8Qx8o4Bg5KK7+wKXJwACoumI2av5EUIzmXcSNKZhQAGqx PAQbK5y1p2OiDrYgCHZCgMHbP2FLb7WNMiE+3c0zrcd5tEkqy6IlCSrGicJm3Kwoi5XxlMC9N b2MrKWziJRdh8yDu+w4Foeec8DLbob+xhJO2Jrc5BbsOCFbKcYx2bJNbKu6Zlt+lMwSvvMPfp d3i66BhCl1xlKebArTAliEES7qax8ibej4Qeu/wxwef2emkcqjB1JJdDyK8WG+5RmSxxOeGYb J5x+hgUKSmK+Zs5dtWceBEG6gRm36qB9zzPLOOrfOEW1v7cJzDUGTeR6GVIzhZOt9gcWayGOf HnJjX5yBzLpVik+HB+mIqg5Ix1xlVJ/FeBkFNyc+wFWAMYL4erxIDjowtn7LyYCYPg+2de6ga PpYHT3Gqbh7KXgQJGcxRAXRp39ubntRqnAq4jYMvbKw/nLxzM5grVxUGaV0HB9B6szjKwfcWq kQcwXhHuBEeUD7OZilHXUGOoSS4CFygSrm99LvtZli/Z2uZOvfiZlm8NfEsQnoCgVV5rsWcCg sbR+pHrrbTwOevrdu7OBjDpgKNHr1F0fdSzKITLKvUCGdXe/3vL7CqTAxj3rE+6Rves6TmenU 3u617P9EJ8ZYMxJIJ//abmDdtILj1olI4WpBbEeUk94Z5ofvGTz1OO+IjJP1bOD97Gi7Iw2H1 sck1plpYdwpmZ4eTm4ZVj08Kj3MIzdcOo8y7gn41nMI8jE5U1ykntKk47gvaNq8qoFmoAmMsi 64pkCowQeCLvU6k9DsPFLIQAapJtGQSm/R6ngTSCYtCIigjNfjOZ4QD5KDsuwXwpGi6/r/ASh 4y0qJfCjWh+U34ISVr0uvj+8kIM=
On Mon, Jan 23, 2023 at 07:31:12PM +0100, Mikael Magnusson wrote:
> On 1/23/23, Dominik Vogt <dominik.vogt@xxxxxx> wrote:
> > On Mon, Jan 23, 2023 at 02:42:05PM +0100, Roman Perepelitsa wrote:
> >> On Mon, Jan 23, 2023 at 2:40 PM Dominik Vogt <dominik.vogt@xxxxxx> wrote:
> >> >
> >> > Is it possible to get timing statistics of shell builtins too?
> >> > Timing "echo" isn't very interesting, but timing loop constructs
> >> > would be:
> >> >
> >> > $ time while foo; do bar done
> >>
> >> This:
> >>
> >> % time ( while foo; do bar; done )
> >
> > That wasn't really the question. Of course I can time a loop by
> > writing a different command, or by putting it in a pipe or file.
> >
> > $ time echo foo | true
> >
> > I just want to get timing statistics of loops either explicitly by
> > prepending "time" or implicitly with REPORTTIME.
>
> As Bart already mentioned, the answer to your question is "no", but
> you can avoid some downsides of the subshell (eg, if your loop has
> side effects that are relevant to the rest of the script etc), by
> using SECONDS:
> % () { typeset -F4 SECONDS=0; sleep 1; () { typeset -F3 SECONDS=0;
> sleep 0.43; echo $SECONDS }; sleep 1; echo $SECONDS }
> 0.431
> 2.4329
> (the downside here is obviously that it doesn't split out cpu/system
> time for you, only elapsed time).
Well, the worst downside for me is that REPORTTIME does not work.
The use case is "oh, that command ran a long time, I'd really
like to know how long it took". I see no solution for that if
re-running the command is no optiuon because it takes too long.
At the moment I'm writing some automation scripts that run for
hours and print their progress. I might want to kill them after a
few hours and see how many seconds they ran and compare it to the
progress output.
Ciao
Dominik ^_^ ^_^
--
Dominik Vogt
Messages sorted by:
Reverse Date,
Date,
Thread,
Author