public static void Clear(int initialSetSize) { RandomTGenerator <int> intGenerator = new RandomTGenerator <int>(InstanceCreators.IntGenerator); int[] startingSet = intGenerator.MakeNewTs(initialSetSize); HashSet <int> theSet = new HashSet <int>(); foreach (var iteration in Benchmark.Iterations) { theSet.UnionWith(startingSet); using (iteration.StartMeasurement()) theSet.Clear(); } }
public static void TestIsProperSupersetEnum() { RandomTGenerator <int> intGenerator = new RandomTGenerator <int>(InstanceCreators.IntGenerator); int[] startingElements = intGenerator.MakeNewTs(MaxStartSize); int[] stuffToCheckProperSuperset = intGenerator.GenerateSelectionSubset(startingElements, InitialSetSize_small); HashSet <int> theSet = new HashSet <int>(); theSet.UnionWith(startingElements); foreach (var iteration in Benchmark.Iterations) { using (iteration.StartMeasurement()) theSet.IsProperSupersetOf(stuffToCheckProperSuperset); } }
public static void Union_NoOp(int startSize, int countToUnion) { RandomTGenerator <int> intGenerator = new RandomTGenerator <int>(InstanceCreators.IntGenerator); int[] startingElements = intGenerator.MakeNewTs(MaxStartSize); int[] stuffToUnion = intGenerator.GenerateMixedSelection(startingElements, countToUnion); HashSet <int> theSet = new HashSet <int>(startingElements); theSet.UnionWith(stuffToUnion); foreach (var iteration in Benchmark.Iterations) { using (iteration.StartMeasurement()) theSet.UnionWith(stuffToUnion); } }
public static void SymmetricExceptEnum(int startSize, int countToExcept) { RandomTGenerator <int> intGenerator = new RandomTGenerator <int>(InstanceCreators.IntGenerator); int[] startingElements = intGenerator.MakeNewTs(startSize); int[] stuffToExcept = intGenerator.GenerateMixedSelection(startingElements, countToExcept); HashSet <int> theSet = new HashSet <int>(); foreach (var iteration in Benchmark.Iterations) { theSet.UnionWith(startingElements); using (iteration.StartMeasurement()) theSet.SymmetricExceptWith(stuffToExcept); theSet.Clear(); } }
public static void Remove(int initialSetSize, int countToRemove) { RandomTGenerator <int> intGenerator = new RandomTGenerator <int>(InstanceCreators.IntGenerator); int[] startingElements = intGenerator.MakeNewTs(initialSetSize); int[] stuffToRemove = intGenerator.GenerateSelectionSubset(startingElements, countToRemove); foreach (var iteration in Benchmark.Iterations) { HashSet <int> theSet = new HashSet <int>(startingElements); using (iteration.StartMeasurement()) { foreach (int thing in stuffToRemove) { theSet.Remove(thing); } } } }
public static void Contains_False(int initialSetSize, int countToCheck) { RandomTGenerator <int> intGenerator = new RandomTGenerator <int>(InstanceCreators.IntGenerator); int[] startingElements = intGenerator.MakeNewTs(initialSetSize); int missingValue = InstanceCreators.IntGenerator_MaxValue + 1; bool present; foreach (var iteration in Benchmark.Iterations) { HashSet <int> theSet = new HashSet <int>(startingElements); using (iteration.StartMeasurement()) { for (int i = 0; i < countToCheck; i++) { present = theSet.Contains(missingValue); } } } }
public static void Contains_True(int initialSetSize, int countToCheck) { RandomTGenerator <int> intGenerator = new RandomTGenerator <int>(InstanceCreators.IntGenerator); int[] startingElements = intGenerator.MakeNewTs(initialSetSize); int[] subsetToCheck = intGenerator.GenerateSelectionSubset(startingElements, countToCheck); bool present; foreach (var iteration in Benchmark.Iterations) { HashSet <int> theSet = new HashSet <int>(startingElements); using (iteration.StartMeasurement()) { foreach (int thing in subsetToCheck) { present = theSet.Contains(thing); } } } }
public static void TestIsProperSubsetHashSet() { RandomTGenerator <int> intGenerator = new RandomTGenerator <int>(InstanceCreators.IntGenerator); int[] startingElements = intGenerator.MakeNewTs(InitialSetSize_small); HashSet <int> theSet = new HashSet <int>(); theSet.UnionWith(startingElements); // this makes perf as bad as possible; avoids fallout case based on count int[] additionalStuffToAdd = intGenerator.MakeNewTs(Math.Max(0, InitialSetSize_small - theSet.Count)); HashSet <int> setToCheckSubset = new HashSet <int>(startingElements); setToCheckSubset.UnionWith(additionalStuffToAdd); foreach (var iteration in Benchmark.Iterations) { using (iteration.StartMeasurement()) theSet.IsProperSubsetOf(setToCheckSubset); } }
public static void Add(int initialSetSize, int countToAdd) { RandomTGenerator <int> intGenerator = new RandomTGenerator <int>(InstanceCreators.IntGenerator); // n is varying start size of set int[] startingElements = intGenerator.MakeNewTs(initialSetSize); int[] stuffToAdd = intGenerator.MakeNewTs(countToAdd); foreach (var iteration in Benchmark.Iterations) { HashSet <int> theSet = new HashSet <int>(startingElements); using (iteration.StartMeasurement()) { foreach (int thing in stuffToAdd) { theSet.Add(thing); } } } }