🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.unix.shell
Article #1376

Re: Why is find so slow (Re: Why use find?)

#1376
From: Chris Torek
Date: Wed, 10 Oct 1990 04:39
46 lines
2254 bytes
In article <F6.rhxm2@cs.psu.edu> flee@guardian.cs.psu.edu (Felix Lee) writes:
>"descend" is fast because it recognizes leaf directories and avoids
>stat()ing the files in that directory.  This is usually a big win,
>since most files tend to be in leaf directories.
>
>"find" can't do this in general, since most of its predicates require
>stat()ing each file, but it wouldn't be too hard to add lazy stat()ing
>to find.  And it may even be worth it.

Quite likely.

4.3BSD-reno's `find' reimplementation (a redistributable version) uses
the C library `fts' routines (from POSIX) which take flags indicating
whether `stat's are desired.  If you say `no', it stats only when this
is required to search the directory.  The new find sets the `I need
stat information' only when at least one predicate requires it.  The
result:

	% cd /usr/src/local/games
	% time find . name obj
	./umoria/obj
	0.3u 0.8s 0:01 91% 35+56k 0+0io 2pf+0w
	% time find . type l
	./umoria/obj
	0.5u 5.2s 0:09 63% 42+66k 94+1io 3pf+0w
	% 

It makes a pretty big difference.  If find said `no stat' and did the
stats only when some predicate actually required it, that would help
make things like

	find . \( name foo or name bar \) and type l

run much faster.  Uncommon?  Not really:

	find / \( fstype local or prune \) \( \
		   \( name '[#,]*'				atime +1 \) \
		or \( \( name '*.bak' or name '.*.bak' \)	atime +3 \) \
		or \( name '.emacs_[0-9]*'			atime +7 \) \
		or \( name core						 \) \
	\) print exec /bin/rm -f {} \;

Incidentally, yes, find still accepts the old syntax (find . -name ...).
-- 
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 405 2750)
Domain:	chris@cs.umd.edu	Path:	uunet!mimsy!chris
Technical Details
Message-ID: <26919@mimsy.umd.edu>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!samsung!uakari.primate.wisc.edu!uflorida!haven!mimsy!chris
References: <1990Sep30.182331.14363@iconsys.uucp> <941@hls0.hls.oz> <F6.rhxm2@cs.psu.edu>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!samsung!uakari.primate.wisc.edu!uflorida!haven!mimsy!chris
From: chris@mimsy.umd.edu (Chris Torek)
Newsgroups: comp.unix.shell,comp.unix.internals
Subject: Re: Why is find so slow (Re: Why use find?)
Message-ID: <26919@mimsy.umd.edu>
Date: 10 Oct 90 04:39:21 GMT
References: <1990Sep30.182331.14363@iconsys.uucp> <941@hls0.hls.oz> <F6.rhxm2@cs.psu.edu>
Organization: U of Maryland, Dept. of Computer Science, Coll. Pk., MD 20742
Lines: 46