Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<blockquote> <p>Can you please suggest a way to improve the performance.</p> </blockquote> <p>Well one obvious improvement would be to use a <code>Dictionary&lt;FileTuple, FileTuple&gt;</code> as well as a <code>List&lt;FileTuple&gt;</code>. That way you wouldn't have an O(N) <code>IndexOf</code> operation on each check. Note that you'll also need to override <code>GetHashCode()</code> - you should already have a warning about this.</p> <p>I doubt that it'll make very much difference though - I'd expect this to be mostly IO-bound.</p> <p>Additionally, I doubt that the filtering and ordering at the end is going to be a significant bottleneck, so using the <code>AsParallel</code> in the final step isn't likely to do much. Of course, you should <em>measure</em> all of this.</p> <p>Finally, the whole method can be made rather simpler, without even needing the <code>HasDuplicate</code> flag or any overriding of <code>Equals</code> / <code>GetHashCode</code>:</p> <pre><code>private List&lt;FileTuple&gt; FindDuplicates() { return Directory.EnumerateFiles(txtFolderPath.Text, "*.*", SearchOption.AllDirectories) .Where(str =&gt; str.Contains(".exe") || str.Contains(".zip") .Select(str =&gt; new FileTuple { FileName = Path.GetFileName(str), ContainingFolder = Path.GetDirectoryName(str)) }) .GroupBy(tuple =&gt; tuple.FileName) .Where(g =&gt; g.Count() &gt; 1) // Only keep duplicates .OrderBy(g =&gt; g.Key) // Order by filename .SelectMany(g =&gt; g) // Flatten groups .ToList(); } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload