Boost logo

Boost :

From: Daniel Yerushalmi (daniel_zy_at_[hidden])
Date: 2003-01-05 11:12:51


Hi All

I have code that iterate on directory tree (the recursive function)
addFolder. I had profiled it (MSVC 6.5)
        Func Func+Child Hit
        Time % Time % Count Function
---------------------------------------------------------
      28.780 43.2 31.818 47.8 567
boost::filesystem::is_directory(class boost::filesystem::path const &)
(operations_posix_windows.obj)
      10.136 15.2 22.666 34.0 151
boost::filesystem::directory_iterator::directory_iterator(class
boost::filesystem::path const &) (operations_posix_windows.obj)
       7.249 10.9 7.249 10.9 592 `anonymous
namespace'::find_next_file(void *,class boost::filesystem::path const
&,struct _WIN32_FIND_DATAA &) (operations_posix_windows.obj)
(operations_posix_windows.obj)

As you can see most of the time is spent in the is_directory function. I
know that (in Win32 - ::FindNextFileA at least) the information for
"is_directory" can be fetched in the "::find_next_file". I suggest to add
m_is_directory attribute to the path class (initial value "unknown") and
have is_directory read from this attribute if possible. (For my application
the is_directory time is swamped by other things but for other directory
iterating applications this may be significant)

profiled function:

addFolder(const fs::path &folder) {
 if (!fs::is_directory(folder)) {
  throw std::domain_error("Folder "+ folder.native_file_string() + " should
have been directory");
 };
 fs::directory_iterator begin(folder);
 for (fs::directory_iterator it = begin; it != fs::directory_iterator();
it++) {
  if (fs::is_directory(*it)) {
   addFolder(*it);
  } else {
        //Do something
   }
  };

 };

Cheers
Daniel Yerushalmi


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk