Reputation: 17553
There are multiple ways to check if a file exists.
The options I know of are:
boost::filesystem exists()
access()
stat()
ifstream is_open()
Does anybody know which of these gives the highest performance?
EDIT: Assume running on /dev/shm where access time is not a factor.
Upvotes: 3
Views: 1859
Reputation: 2684
Modern C++ | Update
C++17 provides this std function:
#include <filesystem>
int main()
{
std::filesystem::path FullPath("C:\\Test.txt");
bool bExists = std::filesystem::exists(FullPath);
}
Upvotes: 2
Reputation: 147036
The runtime here will be dominated by the switch into kernel mode and operation of the filesystem driver- even ignoring disk time. It's highly unlikely that any of them will offer superior performance. Best to pick the one which offers the best interface- boost::filesystem
.
Upvotes: 7