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)

In reply to Re^4: The -d switch isn't working as I expected it to (test to see if its a directory) by sgifford
in thread The -d switch isn't working as I expected it to (test to see if its a directory) by heigold1

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.