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)
  • Comment on Re^4: The -d switch isn't working as I expected it to (test to see if its a directory)
  • Select or Download Code

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
    It's a dual 2Ghz G5, 1GB ram, 10.3.7, MacOS Extended (journaled). I'm only going 3 levels deep so perhaps that's the difference. I don't really think performance is usually a problem here unless you are processing huge numbers of files. Also, if you are actually doing anything with those files, the IO time for that will dominate.

    FWIW, I've noticed that filesystem tests vary greatly depending on architecture, ram, disk speed, moon phase, etc.

    I can see MacOS having a really good cache where chdir is no faster, but I don't understand why it would be slower...

    Not sure what you mean -- chdir was a little faster on my test.