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 23781 invoked from network); 24 Jan 2023 09:33:13 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 24 Jan 2023 09:33:13 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1674552793; b=IXafXwsDqSPEwTfYnyh3psh6/N0oJ3lu8uq8czB1it1FopQO/rTodAfraX2G/JmcIoPe2EXR7n LHqDofHlHkRNO9WnNTole/LOdZatmQnxYfajD/TQqRQBVfAqR6LW7nR+6eTVC7xzFgkAeqd7se UAYPn6N+AKA00LoK27eZ7gbHFp9KIZKlkFMQYXNgoMchTyr84AzQeqFTLxUxqsuwjlTP+CbbID kmISmJ4G7KVq7c+MIWjSLSGHDm+T13mg9Xj3mt1IKm5zFk15hQHQuojX3wvT4R7w5ITlgJz+2U m0sdZUR+XCasnlC5slrRjkZ25N/QayBdrvAwgAJbfdxGKw==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (mail-ej1-f43.google.com) smtp.remote-ip=209.85.218.43; dkim=pass header.d=gmail.com header.s=20210112 header.a=rsa-sha256; dmarc=pass header.from=gmail.com; arc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed; d=zsh.org; s=rsa-20210803; t=1674552793; bh=8sSmTMvmJqCalHPKto3iQ5cUi+FGVilxC83okUE23y4=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:Content-Type:To:Subject:Message-ID:Date:From:References: In-Reply-To:MIME-Version:DKIM-Signature:DKIM-Signature; b=fMF0+nJjR9wleHjCySDabjhccDab1ioK1CTH+WW2hEAZ/JrRYernXsI+x9Qq7bJW42jWdzOYAM 2IjViIYJNN1kTlhB8ssvEjISC3dLe+0mW4tyzBly6NROzf5ah/kB4DYMfD9VsTZf5wdgbkbV0j seskJG3NS0Uisf7xBVjZdvke12/saFI1yqmZUMdlhbZdUUpOD0obJCOsbIQHER5MbFC8iUYPzP AgalUHNNSwaZr6AEqIgPu0m/x39/R8Go8PX5bZHwXfw1TlWqMC9O2GPhJlQN0ekZ3+GLbIzCH0 tqvNsZi0LLlE/zyE7ger5IfUnrIHqCDi2ypSHU734ZrRJQ==; 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-Type:To:Subject:Message-ID: Date:From:References:In-Reply-To:MIME-Version:Reply-To:Cc: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=EhO5wAdMW6pbEBLEbd+EWyEjrq2yuoxExkjHGX6p2V4=; b=rHCQJlCJBztMMTi3EYsqGSZbhj 2SOmhxw7Iz05VIAGNAMXG6+bVHUpY6VlEksgQg1LzyNVtOaOYSDOVJJ0jFsI5bRNAV7lHOomSZp5B 7V3d3Qg8/R3EAyG/TdAd/vxcaDeLk8n9AIFww7F85abn+61VpWJLgFRBmbNBTHI9Vc5MK9Y4b27iB cTdB1mtr4M2U9XSmnCQzqu74fhlY7coP33a2/6JIXnnQao+Cz+THa/vy31NinYyHX59zzX1nGhMBG TcP+AfSkP8XW7OEFmWlPar2XMoK3aTEEWGNJXUjqYvCTxpzsa+gWGHLvxKl239IVkkQeei62SRl9l vlLQ1cSg==; Received: by zero.zsh.org with local id 1pKFg1-000NtZ-2O; Tue, 24 Jan 2023 09:33:13 +0000 Authentication-Results: zsh.org; iprev=pass (mail-ej1-f43.google.com) smtp.remote-ip=209.85.218.43; dkim=pass header.d=gmail.com header.s=20210112 header.a=rsa-sha256; dmarc=pass header.from=gmail.com; arc=none Received: from mail-ej1-f43.google.com ([209.85.218.43]:36700) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_128_GCM_SHA256:128) id 1pKFfR-000NDK-N0; Tue, 24 Jan 2023 09:32:39 +0000 Received: by mail-ej1-f43.google.com with SMTP id kt14so37388671ejc.3 for ; Tue, 24 Jan 2023 01:32:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=to:subject:message-id:date:from:references:in-reply-to:mime-version :from:to:cc:subject:date:message-id:reply-to; bh=EhO5wAdMW6pbEBLEbd+EWyEjrq2yuoxExkjHGX6p2V4=; b=kATYyynp9OLL8NdalIddvOVXcTmxN+l+0xNHbkii5E0/GzJLFcmTq3lvm2nPE30DOF cszLOA37uxPYd7jjfr+ohqCv2uGcvZFn+R142A3jj++d/ubR8xP6K+dbFrqz2i+Xyj/x AVgtT+laDiFR4UojNLA4lD3VExLOOtevn2w3zXpePKz5USHw4wK6HcKp+sPBfpQ/S69J +q6biPRmTbZOoMssXM9iyD3ph8CthLkKgee6SRX+U/XjH8vUb72npYiKXyXTXRhax9DD L718WA4RLsyk3CaIsOvf5AGKD+vH0jqDbypXukB3dJNvwB0s2UpQLxDykmim31W4BaPV o2iw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=to:subject:message-id:date:from:references:in-reply-to:mime-version :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=EhO5wAdMW6pbEBLEbd+EWyEjrq2yuoxExkjHGX6p2V4=; b=phpD0FoZHBpvBMhRZx1DHfkaOmzcgr0QgKfnXPnIF5uuSrb7nYSGvtdceK9pPk7Zn5 Yq6WgbPA9iAPYBxDv4QNZnhAXd6FlFLRe3+8vfEDbT5OwzSOZT5ps3+Ot+F+wFd8q+A4 eYG0VJOTnjhIm+ZLInbIo6iXoh2Dfm4NspXUO9QJj/o/o6Shuc/4C41zEBfQdFTHQxP+ A0k0ZpVmfzG09mzQFh4qwQvVNgGeTh4uuOOmDM+3CXabtGir/0MD9zwATxY29cKj1SA6 WB+93iKWSpH+hrSXcs9yxQ8NW62ovphAEA+l9qdGnMmdZSerl9ygwl1OmhoEoaxIN/6m IHMg== X-Gm-Message-State: AFqh2kqyHeAtLm/X9sqFQuTu8MkB8wpg/EPaQrp+KB9ODbRWIoZ3VSBP TU0fnS8skSvX+38noGUyp/H6U/bPgUYXLV8F+Us= X-Google-Smtp-Source: AMrXdXsYLhVqpXT7UKAv4HQw1PEgD6lP8RQUVAXs+2qn6NQeoYI1mznlUvj2R8hR3GuPhL2+nKQZ9VBLnDKIu9ZoRkY= X-Received: by 2002:a17:907:2b23:b0:877:8b1d:354e with SMTP id gc35-20020a1709072b2300b008778b1d354emr2335435ejc.309.1674552756563; Tue, 24 Jan 2023 01:32:36 -0800 (PST) MIME-Version: 1.0 Received: by 2002:a17:907:c606:b0:7cd:3b2e:124 with HTTP; Tue, 24 Jan 2023 01:32:35 -0800 (PST) In-Reply-To: References: From: Mikael Magnusson Date: Tue, 24 Jan 2023 10:32:35 +0100 Message-ID: Subject: Re: time command with shell builtins To: dominik.vogt@gmx.de, Zsh Users Content-Type: text/plain; charset="UTF-8" X-Seq: 28760 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 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=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. 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). a) zle -N accept-line _accept_line function _accept_line () { zle .reset-prompt } b) zmodload zsh/datetime function precmd_showtime() { if ! (( ${+_zsh_time} )); then return 0; fi if (( $EPOCHSECONDS - $_zsh_time > 10 )); then printf "%i seconds elapsed\n" $(( EPOCHSECONDS - _zsh_time )) fi unset _zsh_time } function preexec_recordtime() { typeset -g _zsh_time _zsh_time=$EPOCHSECONDS } -- Mikael Magnusson