using System.Collections.Generic;
using System.Diagnostics;
namespace ConsoleApplication1
public static void Main(string[] args)
test.someSetRoutineSlower(Test.MakeSet(1));
test.someSetRoutineFaster(Test.MakeSet(1));
var exampleSet = Test.MakeSet(100000);
var t1 = Stopwatch.StartNew();
test.someSetRoutineSlower(exampleSet);
var t2 = Stopwatch.StartNew();
test.someSetRoutineFaster(exampleSet);
Console.WriteLine("Slow: {0,10}", t1.ElapsedTicks);
Console.WriteLine("Fast: {0,10}", t2.ElapsedTicks);
public static HashSet<IExampleAble> MakeSet(int count)
return new HashSet<IExampleAble>(Enumerable.Range(0, count).Select(_ => new IExampleAble()));
HashSet<IExampleAble> alreadyProcessed = MakeSet(10000000);
public void someSetRoutineSlower(HashSet<IExampleAble> exampleSet)
foreach (var item in exampleSet)
if (!alreadyProcessed.Contains(item))
public void someSetRoutineFaster(HashSet<IExampleAble> exampleSet)
exampleSet.ExceptWith(alreadyProcessed);
foreach (var item in exampleSet)