c# - Overly Broad Directory.EnumerateFiles() vs Multiple File.Exists()? -


i updating program which, among other things, checks existence of files within given path. files located in 1 of many subdirectories off of main path. previously, searching entire path files matched given pattern, part of update have separate array containing list of files expect have.

given presence of array, there 2 options considering:

  1. use same call directory.enumeratefiles(startingpath, pattern, searchoption.alldirectories) , check results against array (perhaps through lambda).

  2. use multiple calls file.exists() each member of array.

in average case, talking 3 or fewer files in array given call. in high-end case, still talking less dozen. executions involve hundreds or thousands of calls.

this program resource hog, want go efficient method here. more efficient? there better way? changing datastructure filenames array type possible if lead improvements.

i go second method, bunch of calls file.exists, , in parallelized fashion. there low throughput cost high latency cost on file.exists, speed want asynchronous.

basic idea start with:

var fileexists = myfilepaths     .asparallel()     .todictionary(path => path, path => file.exists(path)); 

(of course, trying first method , doing speed comparison reasonable - i'm giving 'best guess' , comments on second method.)


Comments

Popular posts from this blog

java - Jmockit String final length method mocking Issue -

asp.net - Razor Page Hosted on IIS 6 Fails Every Morning -

c++ - wxwidget compiling on windows command prompt -