|Don't ask to ask, just ask|
Glob and lstatby JediWizard (Deacon)
|on Jul 27, 2012 at 19:39 UTC||Need Help??|
JediWizard has asked for the wisdom of the Perl Monks concerning the following question:
I've been looking through a fairly large code base, updating things and looking for possible preformance improvements. I came across a few bits of code that use:
To get lists of files to process. My tendancy in the past has been to either use File::Find for more complicated searches, or just opendir for more basic situations. Being a good scientist, I decided to put together some benchmarks to determine which would be faster. My results consistently showed the opendir method running substantially faster every time (the sub routines I'm testing with are included below). I'm glad to have done the tests, but surprised by the results, so I decided to poke my head in a little deeper to figure out why. So I ran my tests a few times with strace running to get a look at what was actually going on. What I discovered was that using glob, perl was doing an lstat on every single item it was returning from the glob, which the opendir method clearly did not.
I've looked here, and here, but nothing there has explained why glob is running lstat on every item it returns. Even looking through the various flags available when using the "bsd_glob" method available for export from File::Glob do not appear to make use of the data that lstat would be providing... so why is perl wasting so many compute cycles getting that information?
Any insight would be appreciated.
They say that time changes things, but you actually have to change them yourself.