zsh-users
 help / color / mirror / code / Atom feed
From: Ray Andrews <rayandrews@eastlink.ca>
To: zsh-users@zsh.org
Subject: Re: optimal expansions?
Date: Sat, 20 Apr 2024 16:59:46 -0700	[thread overview]
Message-ID: <922e585e-fb86-41c8-928b-7fd49b310e5b@eastlink.ca> (raw)
In-Reply-To: <8947389c-2243-4b83-b59e-3535c6201228@app.fastmail.com>

[-- Attachment #1: Type: text/plain, Size: 1691 bytes --]



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.

>

[-- Attachment #2: Type: text/html, Size: 3370 bytes --]

  reply	other threads:[~2024-04-21  0:01 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-19 19:22 Ray Andrews
2024-04-19 20:40 ` Lawrence Velázquez
2024-04-19 23:25   ` Ray Andrews
2024-04-20  7:42 ` Roman Perepelitsa
2024-04-20 14:23   ` Ray Andrews
2024-04-20 22:54     ` Lawrence Velázquez
2024-04-20 23:59       ` Ray Andrews [this message]
2024-04-21 12:23     ` Roman Perepelitsa
2024-04-21 14:09       ` Ray Andrews
2024-04-21 14:19         ` Roman Perepelitsa
2024-04-21 16:14           ` Stephane Chazelas
2024-04-21 17:39             ` Roman Perepelitsa
2024-04-21 20:13               ` Stephane Chazelas
2024-04-21 20:46                 ` Lawrence Velázquez

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=922e585e-fb86-41c8-928b-7fd49b310e5b@eastlink.ca \
    --to=rayandrews@eastlink.ca \
    --cc=zsh-users@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).