Given the following for each statement that has some linq in it, I need to iterate through the list as Distinct. So I have a number of places I can add the Distict() statement.
Can someone please explain which solution I should use and why? I'm very new to using AsParallel() so I'm not sure which solution to go with..
Existing Code (which is missing and needs the Distinct())
foreach (var phrase in (something != null
? ListOne.AsParallel()
: ListTwo.AsParallel()))
{
... // irrelevant for this question
}
Option 1: Distincting the entire result.
foreach (var phrase in (something != null
? ListOne.AsParallel()
: ListTwo.AsParallel()).Distinct())
{
... // irrelevant for this question
}
I feel that this would return too much info back (initially).
Option 2: Distinct each list, before Parallel
foreach (var phrase in (something != null
? ListOne.Distinct().AsParallel()
: ListTwo.Distinct().AsParallel()))
{
... // irrelevant for this question
}
Option 3: Distinct each list, after the Parallel
foreach (var phrase in (something != null
? ListOne.AsParallel().Distinct()
: ListTwo.AsParallel().Distinct() ))
{
... // irrelevant for this question
}
Yes - I could create my own test code with stopwatches, etc.. but I'm not so much after the metrics, but more the theory (as to what I should do .. because of XXXXX).
** Before this turns into a subjective question and get closed down, please consider your answers. ** Secondly, I understand the perf here is tiny .. so just to iterate, I'm not so much worried about the -actual- perf difference, but the theoretical difference.