Reputation: 13756
Which is more efficient if there are numerous checks?
bool exists=File.Exists(file);
or
bool exists= check db list of existing files;
Upvotes: 0
Views: 332
Reputation: 42155
It depends.
If you want to check existence of the file, you have no choice but to check the filesystem. Yes, this might be slower than the db call. Db calls are still remote inter-process calls though, and as such can be expensive in their own right.
The answer is to try both, profile, and optimise for the best answer for your specific scenario.
Upvotes: 2
Reputation: 178
If you write the path of the file in a database it is way faster than requesting it by File.Exists, depending on number of files. if you request only one, its not a great diffrence. But if you check more files, a database request is faster and I think you will get the path to the file by database, right?
Upvotes: 1
Reputation: 8733
Of course the second one, since system calls like this one are expensive. It's better to use collective directory listing function and check for the file existence in the memory without file system attention.
Upvotes: 3