zsh-users
 help / color / mirror / code / Atom feed
From: Mikael Magnusson <mikachu@gmail.com>
To: Bart Schaefer <schaefer@brasslantern.com>
Cc: zsh-users@zsh.org
Subject: Re: if the file is not found the files is not found is the file not found
Date: Mon, 5 Mar 2012 01:48:30 +0100	[thread overview]
Message-ID: <CAHYJk3TiYovaiGcirB1L7qK0Dy0BPEsb0dRerYrxw-nYdzc+1Q@mail.gmail.com> (raw)
In-Reply-To: <120304134721.ZM25119@torch.brasslantern.com>

On 4 March 2012 22:47, Bart Schaefer <schaefer@brasslantern.com> wrote:
> On Mar 4,  9:13pm, Mikael Magnusson wrote:
> }
> } >> if () { (( $# )) } arglblargh*(N[1]); then echo yes; else echo no; fi
> } >
> } > (Also, the [1] in your formula is extraneous, but that's a nit.)
> }
> } I like to imagine that it causes less data to be copied around. :)
>
> According to valgrind, for a pattern matching six files the ([1]) saves
> 3 mallocs and 3 frees but uses 346 *more* bytes of memory.  "time" on
> 10 runs of each shows no difference at all.
>
> The ([1]) does begin to win on memory as well when the number of matched
> files grows, but even at 360+ files no difference in time is detectable,
> probably because the vast bulk is taken up by doing the glob in the first
> place.
>
> (e:'[ -f "$REPLY" ]':) takes about 3 times as long and uses 5 times as
> much memory, with or without ([1]) added.  (e:'[[ -f "$REPLY" ]]') is
> better, only double time and triple memory, and is on a par with adding
> (.) as a qualifier.
>
> So there you go. :-)

Heh, thanks for checking :). Btw,
% () { echo $# } *
2411
zsh -c 'repeat 1000 () { (($#)) } *'  6.53s user 0.40s system 98% cpu
6.999 total
zsh -c 'repeat 1000 () { (($#)) } *([1])'  5.97s user 0.38s system 99%
cpu 6.399 total
(numbers are consistent within 0.02s)

So maybe it doesn't save the time it takes to type the [1]. Adding oN
on the other hand,
zsh -c 'repeat 1000 () { (($#)) } *(oN)'  4.81s user 0.40s system 99%
cpu 5.252 total
zsh -c 'repeat 1000 () { (($#)) } *(oN[1])'  4.31s user 0.36s system
99% cpu 4.703 total

For those that don't know, (oN) disables sorting the results of the glob.

-- 
Mikael Magnusson


      reply	other threads:[~2012-03-05  0:48 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-03-04 14:31 meino.cramer
2012-03-04 14:36 ` Moritz Bunkus
2012-03-04 14:37 ` Mikael Magnusson
2012-03-04 18:37   ` Bart Schaefer
2012-03-04 18:48     ` Mikael Magnusson
2012-03-04 19:44       ` Bart Schaefer
2012-03-04 20:13         ` Mikael Magnusson
2012-03-04 21:47           ` Bart Schaefer
2012-03-05  0:48             ` Mikael Magnusson [this message]

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=CAHYJk3TiYovaiGcirB1L7qK0Dy0BPEsb0dRerYrxw-nYdzc+1Q@mail.gmail.com \
    --to=mikachu@gmail.com \
    --cc=schaefer@brasslantern.com \
    --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).