in reply to Re^3: The -d switch isn't working as I expected it to (test to see if its a directory)
in thread The -d switch isn't working as I expected it to (test to see if its a directory)
Update: I misread bluto's numbers somehow and thought his was faster without chdir; re-reading, they're about what I would expect.
Huh, that's hard to explain. What kind of filesystem is it? How deep of a directory is it?
AFAIK, using chdir lets the OS check permissions on all parent directories only once, and after that it can just check permissions on each file. Using the full path requires that the OS look up the permissions information for parent directories much more frequently, and so is slower.
I can see MacOS having a really good cache where chdir is no faster, but I don't understand why it would be slower...
Update: On my wife's G4 with MacOS X 10.3.7 with a journaled MacOS Extended Filesystem on a directory 7 levels deep with 2688 files, I get:
$ ~/tmp/t3 Benchmark: timing 500 iterations of with_chdir, without_chdir... with_chdir: 34 wallclock secs ( 4.39 usr + 12.34 sys = 16.73 CPU) @ 29.89/s (n=500) without_chdir: 62 wallclock secs ( 5.79 usr + 19.93 sys = 25.72 CPU) @ 19.44/s (n=500)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^5: The -d switch isn't working as I expected it to (test to see if its a directory)
by bluto (Curate) on Jan 10, 2005 at 16:37 UTC |