Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!cs.utexas.edu!husc6!psuvax1!flee From: flee@shire.cs.psu.edu (Felix Lee) Newsgroups: comp.unix.wizards Subject: Re: How to write a current directory finder? Message-ID: Date: 2 Apr 89 20:03:00 GMT References: <1368@auspex.auspex.com> Sender: news@psuvax1.cs.psu.edu Organization: Penn State University Computer Science Lines: 18 In-reply-to: mcgrath@paris.Berkeley.EDU's message of 2 Apr 89 18:18:14 GMT Doing a "trace" shows that getwd() does not chdir(). Here is speculation on Sun's getwd() after trying to implement my own and watching a "trace". * It caches its result. Repeated calls to getwd() just make two stat() calls. Trying to time the performance of getwd() by putting it in a loop is meaningless. This is the big win. * It uses /tmp/.getwd to figure out where it is when it crosses a mount point. This is a minor gain. In my version of getwd(), I stat'ed around to find the mount point; commenting out the stat() calls saved about .005s system time (on a Sun4 running SunOS4.0). Any other differences in algorithm (using fstat() instead of stat(), using chdir(), etc.) have little effect on performance. -- Felix Lee flee@shire.cs.psu.edu *!psuvax1!shire!flee