Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: if the file is not found the files is not found is the file not found



On 4 March 2012 22:47, Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> 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



Messages sorted by: Reverse Date, Date, Thread, Author