in reply to opendir slower than ls on large dirs?

Wouldn't (-f $dir/$file) be a faster test for the existence of a (ordinary) file in a directory than either of the other methods?

To explain the comparative behaviour roughly: shelling out has a fixed overhead; the ls command will have been optimised for the platform. opendir/readdir on the other hand has variable overheads, is probably not optimised for a fixed platform, so will begin cheaper but grow with the filecount to eventually overtake the fixed overhead of shelling out.

One world, one people

Replies are listed 'Best First'.
Re^2: opendir slower than ls on large dirs?
by Anonymous Monk on Jul 05, 2005 at 10:18 UTC
    it is by gazillions faster than the things I tried, but i need a wildcard and -f doesn't support that afaik.

    Thanks for the explaination of why ls is quicker on large dirs tho.