Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
RE: Re: Re: time command with shell builtins
- X-seq: zsh-users 28745
- From: zeurkous@xxxxxxxxxxxxxxx
- To: Roman Perepelitsa <roman.perepelitsa@xxxxxxxxx>
- Cc: dominik.vogt@xxxxxx, Zsh Users <zsh-users@xxxxxxx>
- Subject: RE: Re: Re: time command with shell builtins
- Date: Mon, 23 Jan 2023 14:40:16 +0000 (UTC)
- Archived-at: <https://zsh.org/users/28745>
- In-reply-to: <CAN=4vMpZAa3cRqoWfLi8=J=Jt0N5_6egwgRAeRjOF5yFamnmyA@mail.gmail.com>
- List-id: <zsh-users.zsh.org>
- References: <Y86OR0DCpwfSYCXU@localhost> <CAN=4vMqSxEr-K1xg+fGc9kh2qfiZ31fy7hoDBRNHXXF6pH8eEg@mail.gmail.com> <thinkcrap!zeurkous!1674483444.13585@uucp> <CAN=4vMpZAa3cRqoWfLi8=J=Jt0N5_6egwgRAeRjOF5yFamnmyA@mail.gmail.com>
On Mon, 23 Jan 2023 15:23:57 +0100, Roman Perepelitsa <roman.perepelitsa@xxxxxxxxx> wrote:
> On Mon, Jan 23, 2023 at 3:20 PM <zeurkous@xxxxxxxxxxxxxxx> wrote:
>>
>> On Mon, 23 Jan 2023 14:42:05 +0100, Roman Perepelitsa <roman.perepelitsa@xxxxxxxxx> 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 )
>>
>> Doesn't that imply a fork, which will also be timed...?
>
> Yes, it does.
>
>> (Could lead to misleading results, in that case.)
>
> Any tool that measures how long a piece of code takes to run gives you
> an upper bound, so there is nothing new here.
A fork(2) can be particularly expensive, though, so there's an
opportunity to make things better here.
> The standard solution is
> to ensure that the code under benchmark takes a non-trivial amount of
> time to execute. Here's the standard pattern I use:
>
> time ( repeat 1000 code-under-benchmark )
>
> I tune the loop constant so that the benchmark takes around a second.
Me's of course aware of such workarounds (they aren't solutions, though
me agrees that a complete solution would be far beyond our scope).
--zeurkous.
> Roman.
--
Friggin' Machines!
Messages sorted by:
Reverse Date,
Date,
Thread,
Author