I just did some optimizations and was puzzled by this.
My original code looked something like this:
HashSet<IExampleAble> alreadyProcessed;
void someSetRoutineSlower(HashSet<IExampleAble> exampleSet)
{
foreach (var item in exampleSet)
{
if (!alreadyProcessed.Contains(item))
{
}
}
}
It took about 1.2 million ticks to process.
Then I tried the same with the exception:
void someSetRoutineFaster(HashSet<IExampleAble> exampleSet)
{
exampleSet.ExceptWith(alreadyProcessed);
foreach (var item in exampleSet)
{
}
}
and he ran with marks of about 0.4 mil-0.7 mil.
What optimization happens in this case? Is it also necessary to check all the elements, as I do in the first code fragment?
source
share