in reply to opendir slower than ls on large dirs?

Have you tried using glob?

It seems to run quicker that grep/regex/, readdir on large dirs on my system when using a wildcard.


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
"Science is about questioning the status quo. Questioning authority".
The "good enough" maybe good enough for the now, and perfection maybe unobtainable, but that should not preclude us from striving for perfection, when time, circumstance or desire allow.
  • Comment on Re: opendir slower than ls on large dirs?

Replies are listed 'Best First'.
Re^2: opendir slower than ls on large dirs?
by Anonymous Monk on Jul 05, 2005 at 11:59 UTC
    Glob was the sollution! It took less than 1s with the same tests.

    It's still kinda scary that opendir is so slow.

      It's not that opendir is slow, it's calling readdir, building the list, passing that list through to grep, which starts the regex engine once for every file in the list, building the output list and assigning it to the array.

      With large lists, much of that time would expanding memory to stages (powers of 2?) to accomodate the lists as they grow.

      With glob, everything is done within the C code which is entered and exited once.


      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
      "Science is about questioning the status quo. Questioning authority".
      The "good enough" maybe good enough for the now, and perfection maybe unobtainable, but that should not preclude us from striving for perfection, when time, circumstance or desire allow.