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

Re: Fastest way to count # of files?



First ran was slower than this and following ones:

% typeset -F SECONDS; myst=$SECONDS; integer nfiles=0; :
**/*(Ne?'((++nfiles)) && reply=()'?); print $nfiles; echo $(( (SECONDS
- myst) * 1000 ))
80001
1427.3609999982

I.e. 1.4 second

Best regards,
Sebastian Gniazdowski


On 8 September 2016 at 18:08, Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> wrote:
> On Sep 8,  5:36pm, Sebastian Gniazdowski wrote:
> }
> } [...]  The second code reads the whole directory too, but
> } it's slow. First code doesn't provide way to determine # of files
> } read. Is there anything between these two? Something that doesn't
> } store files, but counts them?
>
> Try this:
>
>   integer nfiles=0
>   : **/*(Ne?'((++nfiles)) && reply=()'?)
>   print $nfiles



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