From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.4 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 32757 invoked from network); 24 Jan 2023 10:50:04 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 24 Jan 2023 10:50:04 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1674557404; b=TdhJMNcYrLBXyryzBis56x2zspO2nKusgNnPv30oJibbKaWRnq+WtMYp12i/QjKZtRfR5GAJZp S+MAQ4SEXqFe6ysnSuvVViR7FnTtHlRMnLYzSO6hynzjuIXxEUyen+cg3JHAk9OTCBDq9TNPpe X6U6F8jABZTFl0A1XdHhsGJDp3x79Y59RI4DfPa4ISh46mtZCmgRoi72XrQfxv+BMnBJXVk/Nx rNjpc9opZh71JvnllzqA4ar9Y3J0+TeqBXoes9SGNZRWZjGNIvfgg7PbHayg9eoorEJQc01KNB RJ1nDiaqLXa6+v4J7q0/3S7Dl3MsrA4PDb+fpg5Zc/WqZw==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (mout.gmx.net) smtp.remote-ip=212.227.17.20; dkim=pass header.d=gmx.de header.s=s31663417 header.a=rsa-sha256; dmarc=pass header.from=gmx.de; arc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed; d=zsh.org; s=rsa-20210803; t=1674557404; bh=tw669PillBdYdWRjUAsqBnuOLObcoT3WBURxGPVHDPU=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:Content-Transfer-Encoding:In-Reply-To:Content-Type: MIME-Version:References:Reply-To:Message-ID:Subject:To:From:Date: DKIM-Signature:DKIM-Signature; b=VMsmg6+pTyBjzbrAK+pJLE443TwzEwhWKjFF6/M5WPqIR1sdBWIUV5pgErBhgZZGY9mgNcTvtQ pvOxU1fsFcGoDeO3GfPjFpa0xiIBdDauPzHXwy9AzAgNudvQHPdGcTWNa8v4payHZ8usxNsTh7 vJHxiaI5We2tvNi7DAdyAE07a6seUcJuzve1hp/qXsjiqokGLN6f4cf8odGNt3ZuwR8o48h7MW v3m6KxnTDiwIkjzEfY6OslzSxrX09dfaFbyrNa7yvlhq8hBTfqydrvJHgmYiq3sPLzaxv1h0sf 0kKoKRi+WmXCZb6GkjI60CmcfYbTUtsaYxonF6eyYA0Ueg==; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=zsh.org; s=rsa-20210803; h=List-Archive:List-Owner:List-Post:List-Unsubscribe: List-Subscribe:List-Help:List-Id:Sender:Content-Transfer-Encoding:In-Reply-To :Content-Type:MIME-Version:References:Reply-To:Message-ID:Subject:To:From: Date:Cc:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID; bh=US9Ntqlx8DMnS24FxUHUlQhVTRyDQpxEUgg0gep/R0w=; b=A9FEV9M93ZE8z6vl7REC5jCE7e l2KSXvHARRO/48lswO85fYFCQP6FT8N7y47vhMRoJA0kLmXtaNJ+HcGNzWv/fTWTKMJa7Obg65ik1 vc3QVmfCuCfdVddhy6we2c9mff1jCL37BLxOxXRv3bz5uFJ7YGrB4DunntI4h29a7A1ePaYKFNaoV UlxXuDatir/4FpwArV2ia70EfOtc5MwRIPLgjyD/jJHG7s7+DQqymZ5ZFCeSkfR9fZfzXVlZ2R6Fc TRzKWfj4VEWDYvzWdsrOtledZos5YfNryoVs11vUDfFeYBO5VWAJjmBxMrj1a/C9KpNT8xk2EXcyv 5pvfZMBQ==; Received: by zero.zsh.org with local id 1pKGsM-0002jQ-Tu; Tue, 24 Jan 2023 10:50:02 +0000 Authentication-Results: zsh.org; iprev=pass (mout.gmx.net) smtp.remote-ip=212.227.17.20; dkim=pass header.d=gmx.de header.s=s31663417 header.a=rsa-sha256; dmarc=pass header.from=gmx.de; arc=none Received: from mout.gmx.net ([212.227.17.20]:38677) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_256_GCM_SHA384:256) id 1pKGr5-00023H-HG; Tue, 24 Jan 2023 10:48:45 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.de; s=s31663417; t=1674557322; bh=tw669PillBdYdWRjUAsqBnuOLObcoT3WBURxGPVHDPU=; h=X-UI-Sender-Class:Date:From:To:Subject:Reply-To:References: In-Reply-To; b=pTOsuZt99sUqSjExzO3J6fpLs9ZF5RIf1P5g4hF9EqrahMOGdP9as+Ba+/3ycEKNN A92iy8JW9O9YsQbcexJGgUSZ4ltWD0YbIiFjtQYST3nXEdOizBw6mAmAQJFyqM3eRp y61NjrXO4aw3HTlX3ODfVzuVcwCzqmpz0ONFiM12kvBmsbxN235ToF0wecZ+tIgfhC exj4ghHGjrwuT7zn+keNEH7mQ/VTti4CKJqyGxqmYNKaiJ0npPfN3Vv/ug+DZbNg81 cIfdWwgnhUbqCMlvt+jNAmLX1PP3CjyvasKD9hqiF4Dwfc5UzS+k9UlP3CmaahcRJE Qgll9ggFduXYw== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from limone.obstwiese ([46.223.163.203]) by mail.gmx.net (mrgmx104 [212.227.17.168]) with ESMTPSA (Nemesis) id 1MpUUm-1oumsY32Jo-00pqCb for ; Tue, 24 Jan 2023 11:48:42 +0100 Received: from luthien by limone.obstwiese with local (Exim 4.94.2) (envelope-from ) id 1pKGr1-0001pJ-Ro; Tue, 24 Jan 2023 11:48:39 +0100 Date: Tue, 24 Jan 2023 11:48:39 +0100 From: Dominik Vogt To: zsh-users@zsh.org Subject: Re: time command with shell builtins Message-ID: Reply-To: dominik.vogt@gmx.de Mail-Followup-To: zsh-users@zsh.org References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Provags-ID: V03:K1:WlBuhOjGjoQ9x8/e2m90199yyKv4mJOkKw6QZFoS0gSz2JOzPiX bujrTYtF7erdy4WM5bl1/HM5uVSc+ylh9WYrSDUSQnCTdkLiOUgdMTr/XBI32W5cStz67xU QTtC8nXeyDLt3I2sdLKxACaF/WEbMbtd4SdjP31w6UqRNWEkz6Qn3hc5Jx36ATMcipSvjqB 9Li27ta41kQMT5p/en8fw== UI-OutboundReport: notjunk:1;M01:P0:mn57CxFjQBo=;raZa0qTv4aGgazPRvvZRBPIzCKP CORGLWaU+QLwpZbcOyucgzdsw9VoUGSazMh5tt3B+mxo7RUrPVl3hbmnuJqfSOrclD6UEHTVu lGwryP1xUtPs4l7HdbAhmqlljcD9CcDMCTiubJYK99cfEtdevW/vuA9oABNaRskt2nM7jCZzm Te1EURtX1jWwjOEQPnB8kNuV3DqAWir+1G09Y50Xz+vBjqBAX9GiSSD58xFB7j0Zo0Nd4tozO CW/gaS9w5jd89/LDK8TuCGXU5BVHR4cmBraWi/jAfg53Jna5sAq/bqVpMztmSc8UJC8PZYr9B bRxgjBvUbRzDOWhDRFYiXLwYhlzaHSOQ+K8+mLBjbGuMg50WeeuuyG0Uw8mIAjPAOuq1eFCV1 s5vAd3Qjpz3sMu6ZvZBTTfVn75vugsmsS1o++4TppQNnzYP2jkc8wLa+0aXHZjCRvA1h0KaP7 KmrqsP1H9eCwOP39vCbdfEZ1qK6Nodyt2qVlp2sArgX4oVT4PG4qW0iq/T1dIb5RlGQdb3XK9 fLItkYiI27ycAyhg4YhHdn03eydh6D7BzLviHJwEa7Cfq4wLAHpJT8PnYYTe6/2fGk3eNxtSr lRwkdTi1CHo7696a4SV1iVbXKqQpJi/yNIY2uV2Wqb7VHpCCHX7KM+EQg9fZP1338gn74ZQ/f Bgjw+4cZzSQqHBNCu/doIzsjOMTl1cFDPpABgF1VT6qaLVEDn01bYfAIUuMvQjC7Qzl60asDJ V+OJE0Z5X8LXThEuQcqpVh94OY84m39BgFz7twPAHqzJrQ6+7xG2eEfuIclgMmFNRzDF7psnF coPmiz8VS62yozOJTQcYsKWro6CEgK15vr1UzooVBifmazLnne9TEs2EtIebfsnIXSwhxa9iU xFFJRzfiNuaJVFRN/q2oGQy1Xq5b8piOHBFVEE58v6NLHU0qpKIZdKmpkl3F8ie8r/+qkp8bv Jg9CFQ== Content-Transfer-Encoding: quoted-printable X-Seq: 28762 Archived-At: X-Loop: zsh-users@zsh.org Errors-To: zsh-users-owner@zsh.org Precedence: list Precedence: bulk Sender: zsh-users-request@zsh.org X-no-archive: yes List-Id: List-Help: , List-Subscribe: , List-Unsubscribe: , List-Post: List-Owner: List-Archive: On Tue, Jan 24, 2023 at 10:32:35AM +0100, Mikael Magnusson wrote: > On 1/23/23, Dominik Vogt wrote: > > On Mon, Jan 23, 2023 at 07:31:12PM +0100, Mikael Magnusson wrote: > >> On 1/23/23, Dominik Vogt 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 > >> >> 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=3D0; sleep 1; () { typeset -F3 SECONDS=3D0= ; > >> 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. > > What you can do at the moment is a) put the time in your prompt (and > reset the prompt on accept-line), b) save the current time in preexec > and compare it against the current time in precmd and print it out if > it exceeds some threshold(, c) or both). Good idea. This is what I use now: =2D- snip -- autoload -Uz add-zsh-hook zmodload zsh/datetime function preexec_recordtime() { typeset -g _zsh_time _zsh_time=3D"$EPOCHSECONDS" } add-zsh-hook preexec preexec_recordtime function __prompt_get_displaytime () { if ! (( ${+_zsh_time} )); then return 0; fi if ! (( ${+REPORTTIME} )); then return 0; fi if (( $EPOCHSECONDS - $_zsh_time > $REPORTTIME )); then printf " $[EPOCHSECONDS - _zsh_time]s" fi unset _zsh_time } PS1=3D"<...>$(__prompt_get_displaytime)<...>" =2D- snip -- The measurement is good enough at the moment. Putting the result in the prompt has the advantage of not polluting the terminal. Ciao Dominik ^_^ ^_^ =2D- Dominik Vogt