young wrote:
I have 2 functions for read files list in one directory. One uses Win32 and one uses boost:
void GetFilesWin32(std::string dir) { std::vectorstd::string vFiles; std::string f = dir + "*.*"; std::string file; WIN32_FIND_DATA findFileData; HANDLE h = FindFirstFile(f.c_str(), &findFileData); if(h != INVALID_HANDLE_VALUE) { do { if((findFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != FILE_ATTRIBUTE_DIRECTORY) { file = findFileData.cFileName; vFiles.push_back( file); } } while( FindNextFile( h, &findFileData) != 0); } FindClose(h); }
void GetFilesBoost(std::string dir) { namespace fs = boost::filesystem; std::vectorstd::string vFiles; fs::path path(dir); fs::directory_iterator end_dir; for(fs::directory_iterator it(path); it != end_dir; it++) { if(!(fs::is_directory(it->status()))) { vFiles.push_back(it->path().filename().string()); } } }
Boost takes 1.00 ms while Win32 taks 0.15 ms for same directory. Why?
How about trying out the profiling facilites available with your development system. I"ve used both the ones available with gcc and recent versions of VC IDE and found them very useful for answering such questions. Robert Ramey