From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.1 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_EF,HEADER_FROM_DIFFERENT_DOMAINS,HTML_MESSAGE, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham autolearn_force=no version=3.4.4 Received: from zero.zsh.org (zero.zsh.org [IPv6:2a02:898:31:0:48:4558:7a:7368]) by inbox.vuxu.org (Postfix) with ESMTP id 4B47220282 for ; Sun, 21 Apr 2024 02:01:24 +0200 (CEST) ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1713657684; b=i9i3T8iBJNVQSRf8PAJWBPbA3lomT55FDvV/lAhM9EspJ+uFNxfFddv7ZyM7hUjdheE6YLmwJM 6Sz3pgq1HcbjMrHHcL6sxFGTFNOpiAcReSbf32zErja7fYLrbJ7jmUVY/T2a5JGoU9mzpnI8RT E6GrJibHeFnR4kWcx3oaJrsL364KL4KAf50NOT0lhWKV3b/8WoeI9S2SZCMDkMFaKvVgHE58kL LBjn9mvA7QPGDRlJkOEspoBl6TsWAYd6wk18JP+9fV8CsOtgp+mXB7SpER5n0wj9QxakM7oWXK PoSQx52T8R0+cVblz0f6rv5PEIeIy1oVI7t6oyaUSzqdug==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (mta01.eastlink.ca) smtp.remote-ip=24.224.136.30; dmarc=none header.from=eastlink.ca; arc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed; d=zsh.org; s=rsa-20210803; t=1713657684; bh=xK+0IH9Kzed9qD2IxtyRzuVsck7OOFgof4BUb8W6Kk4=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:In-Reply-To:From:References:To:Subject:MIME-Version:Date: Message-ID:Content-Type:DKIM-Signature; b=nwiOPlUkxTTU+XGiCXUlnu6UQR2MpsRPrKqeevrk9zSqgMlInrpNB5y2A02GXRViLWUrfdsltF DOggJlbWG67w+IjJ8Jl7gMkxf4o7UqPcx+3VWnMXsUz4vSG/joTRIC0AlWGemB6W21lZaX2DRp G51UUXXI7oi12MQX9FxrZWv6N+UrvT7OpI9wo9ge7l9To08RwUEjrcP1u8INMCulBLqOv/MHjr lZylBepg/A2HHuDNE6e1WcUZRpxboty8WYgGkM/IbtqLX3iDNKrRnKGqGWwSlBAQDIkS8CVFsQ H4h+qp0107SS9EZihihHzNJeNRZF2CUgtJiX50Hvcz0KRA==; 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:In-reply-to:From:References:To: Subject:MIME-version:Date:Message-id:Content-type:Reply-To:Cc: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=dAo9U5eMSVToXRQaYYzYSt59xBafnq4jkrue5voFfU0=; b=g8lF621iTIhAkBqIjdhNRqTKOy rbtwZ00sjEvOnz5wX4447dQ7xkwKjFY+QXDeGDy2GY2RJqWLYGlqiNnjQ7AvuT4Xtr/rTs7OUJx0D n26QKaGGUOCWFy/ssKmb49fsWoDJFNUhn7O3EM0WLFAP0Wa9cYAAdSvSBbTxOTZJnUQnlXt4oYHXx L3WLgSflNRFYEzWdbhO7XNWaAGxVtaNIUdHtwAeDcht+qtrTXa1XEW5POm0MILA5JzzpZpuDy8LBD UGxVOlFhv4uOigOI0r7lnR3P+49o028LcORjnXYzLfuzqF2LU4EUz2Ovg3iX2Imfya66IW/hWFBNX Mo/VxIgg==; Received: by zero.zsh.org with local id 1ryKe4-000GWJ-ML; Sun, 21 Apr 2024 00:01:24 +0000 Authentication-Results: zsh.org; iprev=pass (mta01.eastlink.ca) smtp.remote-ip=24.224.136.30; dmarc=none header.from=eastlink.ca; arc=none Received: from mta01.eastlink.ca ([24.224.136.30]:49559) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_128_GCM_SHA256:128) id 1ryKcW-000FhA-Bw; Sat, 20 Apr 2024 23:59:48 +0000 Received: from csp02.eastlink.ca ([71.7.199.167]) by mta01.eastlink.ca ([24.224.136.30]) with ESMTPS id <0SC920USJMNFCRE0@mta01.eastlink.ca> for zsh-users@zsh.org; Sat, 20 Apr 2024 20:59:47 -0300 (ADT) Received: from [192.168.0.11] (host-24-207-19-13.public.eastlink.ca [24.207.19.13]) by csp02.eastlink.ca ([71.7.199.167]) with ESMTPSA id yKcUr2fCK5TsryKcUrI9KY (version=TLSv1_2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256); Sat, 20 Apr 2024 20:59:47 -0300 X-Authority-Analysis: v=2.4 cv=deIj3mXe c=1 sm=1 tr=0 ts=662456f3 a=e7T7DzMKK1R988ZCg0wLyw==:117 a=e7T7DzMKK1R988ZCg0wLyw==:17 a=r77TgQKjGQsHNAKrUKIA:9 a=U7NajvXhdvLe_W8AfpMA:9 a=3ZKOabzyN94A:10 a=QEXdDO2ut3YA:10 a=ZLGELXoPAAAA:8 a=k13eDADMAr2TY_67rogA:9 a=UeX-0D-iMEI48yKB:21 a=_W_S_7VecoQA:10 a=CFiPc5v16LZhaT-MVE1c:22 X-Vade-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrudekhedgvdekucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecugfetuffvnffkpffmpdfqfgfvnecuuegrihhlohhuthemuceftddtnecunecujfgurheptgfkffggfgfuvfhfhfgjsegrtderredtvdejnecuhfhrohhmpeftrgihucetnhgurhgvfihsuceorhgrhigrnhgurhgvfihssegvrghsthhlihhnkhdrtggrqeenucggtffrrghtthgvrhhnpefhteethfevgeeuvdelgefgvdevudefueduffdvgfelvddvgfdtieegueeuleeifeenucfkphepvdegrddvtdejrdduledrudefnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehinhgvthepvdegrddvtdejrdduledrudefpdhhvghloheplgduledvrdduieekrddtrdduudgnpdhmrghilhhfrhhomheprhgrhigrnhgurhgvfihssegvrghsthhlihhnkhdrtggrpdhnsggprhgtphhtthhopedvpdhrtghpthhtohepreerpdhrtghpthhtohepiihshhdquhhsvghrshesiihshhdrohhrghdpghgvthdqkghiphfrrghsshifugepthhruhgv X-Vade-Score: 0 X-Vade-State: 0 X-EL-AUTH: rayandrews@eastlink.ca Content-type: multipart/alternative; boundary="------------3VzT8V50xmTU6dMnfGsnH60C" Message-id: <922e585e-fb86-41c8-928b-7fd49b310e5b@eastlink.ca> Date: Sat, 20 Apr 2024 16:59:46 -0700 MIME-version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: optimal expansions? To: zsh-users@zsh.org References: <53fab6be-26d7-4de5-844f-ffc295d9a494@eastlink.ca> <3d15311d-b5fa-4a55-a17e-e61fcdded7d0@eastlink.ca> <8947389c-2243-4b83-b59e-3535c6201228@app.fastmail.com> Content-language: en-US From: Ray Andrews In-reply-to: <8947389c-2243-4b83-b59e-3535c6201228@app.fastmail.com> X-Seq: 29845 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: This is a multi-part message in MIME format. --------------3VzT8V50xmTU6dMnfGsnH60C Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit On 2024-04-20 15:54, Lawrence Velázquez wrote: > The "-P" option tells "print" to interpret prompt escapes like "%B" > and "%F" Right, I remember that now, the '%' escapes.  So there's an advantage to using that method I take it. Never used it anywhere but in my prompt.  So those escapes are part of the wider world then. > (see zshmisc(1)), allowing you to avoid hardcoding ECMA-48 > escape sequences. The "${pkg//\%/%%}" expansion interpolates the > package name with all "%" characters escaped. Ok, I can parse that now. >> Seems we want '-r' most of the time. > Yes, unless you actually do want "print" to interpret substrings > like "\n". Sometimes you do, sometimes you don't. If the operands > are dynamic and not under your control, you generally don't. Yup, with me using newlines to split arrays, I had to avoid it. It's almost amusing, I had the newlines thing exactly backwards but still managed to make my functions work. > That's because Roman's solution uses "read" to stream the output > from "apt-file" instead of saving it all and postprocessing it. Right, it has to be more efficient. > If speed is a concern... Not in practice, it was just a comment. ... > % apt-file search .txt | wc -l > 138962 > % for x in ray roman awk; do eval time ./af_$x .txt; done >/dev/null > ./af_ray .txt 39.43s user 1.74s system 102% cpu 40.099 total > ./af_roman .txt 12.99s user 24.97s system 130% cpu 29.069 total > ./af_awk .txt 3.08s user 1.02s system 131% cpu 3.131 total That's astonishing.  awk that much faster.  And the code is more complex to look at.  I'd have expected zsh native code to always be faster than calling an external program.  Thereyago. > --------------3VzT8V50xmTU6dMnfGsnH60C Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 8bit

On 2024-04-20 15:54, Lawrence Velázquez wrote:
The "-P" option tells "print" to interpret prompt escapes like "%B"
and "%F"
Right, I remember that now, the '%' escapes.  So there's an advantage to using that method I take it. Never used it anywhere but in my prompt.  So those escapes are part of the wider world then.
 (see zshmisc(1)), allowing you to avoid hardcoding ECMA-48
escape sequences.  The "${pkg//\%/%%}" expansion interpolates the
package name with all "%" characters escaped.
Ok, I can parse that now. 
Seems we want '-r' most of the time.
Yes, unless you actually do want "print" to interpret substrings
like "\n".  Sometimes you do, sometimes you don't.  If the operands
are dynamic and not under your control, you generally don't.
Yup, with me using newlines to split arrays, I had to avoid it.  It's almost amusing, I had the newlines thing exactly backwards but still managed to make my functions work. 
That's because Roman's solution uses "read" to stream the output
from "apt-file" instead of saving it all and postprocessing it.
Right, it has to be more efficient. 
If speed is a concern...
Not in practice, it was just a comment.
...
% apt-file search .txt | wc -l
138962
% for x in ray roman awk; do eval time ./af_$x .txt; done >/dev/null
./af_ray .txt  39.43s user 1.74s system 102% cpu 40.099 total
./af_roman .txt  12.99s user 24.97s system 130% cpu 29.069 total
./af_awk .txt  3.08s user 1.02s system 131% cpu 3.131 total
That's astonishing.  awk that much faster.  And the code is more complex to look at.  I'd have expected zsh native code to always be faster than calling an external program.  Thereyago. 



--------------3VzT8V50xmTU6dMnfGsnH60C--