diff --git a/src/benchmarks/corefx/Common/UniqueValuesGenerator.cs b/src/benchmarks/corefx/Common/UniqueValuesGenerator.cs index 0ce2dcb6952..fcf006a8a47 100644 --- a/src/benchmarks/corefx/Common/UniqueValuesGenerator.cs +++ b/src/benchmarks/corefx/Common/UniqueValuesGenerator.cs @@ -6,9 +6,11 @@ namespace Helpers { internal static class UniqueValuesGenerator { + private const int Seed = 12345; // we always use the same seed to have repeatable results! + internal static T[] GenerateArray(int count) { - var random = new Random(12345); // we always use the same seed to have repeatable results! + var random = new Random(Seed); var uniqueValues = new HashSet(); @@ -25,7 +27,7 @@ internal static T[] GenerateArray(int count) internal static Dictionary GenerateDictionary(int count) { - var random = new Random(12345); // we always use the same seed to have repeatable results! + var random = new Random(Seed); var dictionary = new Dictionary(); diff --git a/src/benchmarks/corefx/System.Collections/Contains/ContainsFalse.cs b/src/benchmarks/corefx/System.Collections/Contains/ContainsFalse.cs index 9af028c8400..7e78798d9a1 100644 --- a/src/benchmarks/corefx/System.Collections/Contains/ContainsFalse.cs +++ b/src/benchmarks/corefx/System.Collections/Contains/ContainsFalse.cs @@ -17,15 +17,15 @@ public class ContainsFalse private T[] _array; private List _list; - private LinkedList _linkedlist; - private HashSet _hashset; + private LinkedList _linkedList; + private HashSet _hashSet; private Queue _queue; private Stack _stack; - private SortedSet _sortedset; - private ImmutableArray _immutablearray; - private ImmutableHashSet _immutablehashset; - private ImmutableList _immutablelist; - private ImmutableSortedSet _immutablesortedset; + private SortedSet _sortedSet; + private ImmutableArray _immutableArray; + private ImmutableHashSet _immutableHashSet; + private ImmutableList _immutableList; + private ImmutableSortedSet _immutableSortedSet; [Params(Utils.DefaultCollectionSize)] public int Size; @@ -39,15 +39,15 @@ public void Setup() _array = secondHalf; _list = new List(secondHalf); - _linkedlist = new LinkedList(secondHalf); - _hashset = new HashSet(secondHalf); + _linkedList = new LinkedList(secondHalf); + _hashSet = new HashSet(secondHalf); _queue = new Queue(secondHalf); _stack = new Stack(secondHalf); - _sortedset = new SortedSet(secondHalf); - _immutablearray = Immutable.ImmutableArray.CreateRange(secondHalf); - _immutablehashset = Immutable.ImmutableHashSet.CreateRange(secondHalf); - _immutablelist = Immutable.ImmutableList.CreateRange(secondHalf); - _immutablesortedset = Immutable.ImmutableSortedSet.CreateRange(secondHalf); + _sortedSet = new SortedSet(secondHalf); + _immutableArray = Immutable.ImmutableArray.CreateRange(secondHalf); + _immutableHashSet = Immutable.ImmutableHashSet.CreateRange(secondHalf); + _immutableList = Immutable.ImmutableList.CreateRange(secondHalf); + _immutableSortedSet = Immutable.ImmutableSortedSet.CreateRange(secondHalf); } [Benchmark] @@ -57,7 +57,7 @@ public bool Array() var collection = _array; var notFound = _notFound; for (int i = 0; i < notFound.Length; i++) - result = collection.Contains(notFound[i]); + result ^= collection.Contains(notFound[i]); return result; } @@ -68,7 +68,7 @@ public bool List() var collection = _list; var notFound = _notFound; for (int i = 0; i < notFound.Length; i++) - result = collection.Contains(notFound[i]); + result ^= collection.Contains(notFound[i]); return result; } @@ -82,7 +82,7 @@ private bool Contains(ICollection collection) bool result = default; var notFound = _notFound; for (int i = 0; i < notFound.Length; i++) - result = collection.Contains(notFound[i]); + result ^= collection.Contains(notFound[i]); return result; } @@ -90,10 +90,10 @@ private bool Contains(ICollection collection) public bool LinkedList() { bool result = default; - var collection = _linkedlist; + var collection = _linkedList; var notFound = _notFound; for (int i = 0; i < notFound.Length; i++) - result = collection.Contains(notFound[i]); + result ^= collection.Contains(notFound[i]); return result; } @@ -101,10 +101,10 @@ public bool LinkedList() public bool HashSet() { bool result = default; - var collection = _hashset; + var collection = _hashSet; var notFound = _notFound; for (int i = 0; i < notFound.Length; i++) - result = collection.Contains(notFound[i]); + result ^= collection.Contains(notFound[i]); return result; } @@ -115,7 +115,7 @@ public bool Queue() var collection = _queue; var notFound = _notFound; for (int i = 0; i < notFound.Length; i++) - result = collection.Contains(notFound[i]); + result ^= collection.Contains(notFound[i]); return result; } @@ -126,7 +126,7 @@ public bool Stack() var collection = _stack; var notFound = _notFound; for (int i = 0; i < notFound.Length; i++) - result = collection.Contains(notFound[i]); + result ^= collection.Contains(notFound[i]); return result; } @@ -134,10 +134,10 @@ public bool Stack() public bool SortedSet() { bool result = default; - var collection = _sortedset; + var collection = _sortedSet; var notFound = _notFound; for (int i = 0; i < notFound.Length; i++) - result = collection.Contains(notFound[i]); + result ^= collection.Contains(notFound[i]); return result; } @@ -145,10 +145,10 @@ public bool SortedSet() public bool ImmutableArray() { bool result = default; - var collection = _immutablearray; + var collection = _immutableArray; var notFound = _notFound; for (int i = 0; i < notFound.Length; i++) - result = collection.Contains(notFound[i]); + result ^= collection.Contains(notFound[i]); return result; } @@ -156,10 +156,10 @@ public bool ImmutableArray() public bool ImmutableHashSet() { bool result = default; - var collection = _immutablehashset; + var collection = _immutableHashSet; var notFound = _notFound; for (int i = 0; i < notFound.Length; i++) - result = collection.Contains(notFound[i]); + result ^= collection.Contains(notFound[i]); return result; } @@ -167,10 +167,10 @@ public bool ImmutableHashSet() public bool ImmutableList() { bool result = default; - var collection = _immutablelist; + var collection = _immutableList; var notFound = _notFound; for (int i = 0; i < notFound.Length; i++) - result = collection.Contains(notFound[i]); + result ^= collection.Contains(notFound[i]); return result; } @@ -178,10 +178,10 @@ public bool ImmutableList() public bool ImmutableSortedSet() { bool result = default; - var collection = _immutablesortedset; + var collection = _immutableSortedSet; var notFound = _notFound; for (int i = 0; i < notFound.Length; i++) - result = collection.Contains(notFound[i]); + result ^= collection.Contains(notFound[i]); return result; } } diff --git a/src/benchmarks/corefx/System.Collections/Contains/ContainsKeyFalse.cs b/src/benchmarks/corefx/System.Collections/Contains/ContainsKeyFalse.cs index 8c35d4cf7c0..c7bff8d14e9 100644 --- a/src/benchmarks/corefx/System.Collections/Contains/ContainsKeyFalse.cs +++ b/src/benchmarks/corefx/System.Collections/Contains/ContainsKeyFalse.cs @@ -18,11 +18,11 @@ public class ContainsKeyFalse private Dictionary _source; private Dictionary _dictionary; - private SortedList _sortedlist; - private SortedDictionary _sorteddictionary; - private ConcurrentDictionary _concurrentdictionary; - private ImmutableDictionary _immutabledictionary; - private ImmutableSortedDictionary _immutablesorteddictionary; + private SortedList _sortedList; + private SortedDictionary _sortedDictionary; + private ConcurrentDictionary _concurrentDictionary; + private ImmutableDictionary _immutableDictionary; + private ImmutableSortedDictionary _immutableSortedDictionary; [Params(Utils.DefaultCollectionSize)] public int Size; @@ -35,11 +35,11 @@ public void Setup() _source = values.Skip(Size).Take(Size).ToDictionary(item => item, item => (TValue)(object)item); _dictionary = new Dictionary(_source); - _sortedlist = new SortedList(_source); - _sorteddictionary = new SortedDictionary(_source); - _concurrentdictionary = new ConcurrentDictionary(_source); - _immutabledictionary = Immutable.ImmutableDictionary.CreateRange(_source); - _immutablesorteddictionary = Immutable.ImmutableSortedDictionary.CreateRange(_source); + _sortedList = new SortedList(_source); + _sortedDictionary = new SortedDictionary(_source); + _concurrentDictionary = new ConcurrentDictionary(_source); + _immutableDictionary = Immutable.ImmutableDictionary.CreateRange(_source); + _immutableSortedDictionary = Immutable.ImmutableSortedDictionary.CreateRange(_source); } [Benchmark] @@ -49,7 +49,7 @@ public bool Dictionary() var collection = _dictionary; var notFound = _notFound; for (int i = 0; i < notFound.Length; i++) - result = collection.ContainsKey(notFound[i]); + result ^= collection.ContainsKey(notFound[i]); return result; } @@ -63,7 +63,7 @@ public bool ContainsKey(IDictionary collection) bool result = default; var notFound = _notFound; for (int i = 0; i < notFound.Length; i++) - result = collection.ContainsKey(notFound[i]); + result ^= collection.ContainsKey(notFound[i]); return result; } @@ -71,10 +71,10 @@ public bool ContainsKey(IDictionary collection) public bool SortedList() { bool result = default; - var collection = _sortedlist; + var collection = _sortedList; var notFound = _notFound; for (int i = 0; i < notFound.Length; i++) - result = collection.ContainsKey(notFound[i]); + result ^= collection.ContainsKey(notFound[i]); return result; } @@ -82,10 +82,10 @@ public bool SortedList() public bool SortedDictionary() { bool result = default; - var collection = _sorteddictionary; + var collection = _sortedDictionary; var notFound = _notFound; for (int i = 0; i < notFound.Length; i++) - result = collection.ContainsKey(notFound[i]); + result ^= collection.ContainsKey(notFound[i]); return result; } @@ -93,10 +93,10 @@ public bool SortedDictionary() public bool ConcurrentDictionary() { bool result = default; - var collection = _concurrentdictionary; + var collection = _concurrentDictionary; var notFound = _notFound; for (int i = 0; i < notFound.Length; i++) - result = collection.ContainsKey(notFound[i]); + result ^= collection.ContainsKey(notFound[i]); return result; } @@ -104,10 +104,10 @@ public bool ConcurrentDictionary() public bool ImmutableDictionary() { bool result = default; - var collection = _immutabledictionary; + var collection = _immutableDictionary; var notFound = _notFound; for (int i = 0; i < notFound.Length; i++) - result = collection.ContainsKey(notFound[i]); + result ^= collection.ContainsKey(notFound[i]); return result; } @@ -115,10 +115,10 @@ public bool ImmutableDictionary() public bool ImmutableSortedDictionary() { bool result = default; - var collection = _immutablesorteddictionary; + var collection = _immutableSortedDictionary; var notFound = _notFound; for (int i = 0; i < notFound.Length; i++) - result = collection.ContainsKey(notFound[i]); + result ^= collection.ContainsKey(notFound[i]); return result; } } diff --git a/src/benchmarks/corefx/System.Collections/Contains/ContainsKeyTrue.cs b/src/benchmarks/corefx/System.Collections/Contains/ContainsKeyTrue.cs index 5982bbb8945..6f580767c00 100644 --- a/src/benchmarks/corefx/System.Collections/Contains/ContainsKeyTrue.cs +++ b/src/benchmarks/corefx/System.Collections/Contains/ContainsKeyTrue.cs @@ -18,11 +18,11 @@ public class ContainsKeyTrue private Dictionary _source; private Dictionary _dictionary; - private SortedList _sortedlist; - private SortedDictionary _sorteddictionary; - private ConcurrentDictionary _concurrentdictionary; - private ImmutableDictionary _immutabledictionary; - private ImmutableSortedDictionary _immutablesorteddictionary; + private SortedList _sortedList; + private SortedDictionary _sortedDictionary; + private ConcurrentDictionary _concurrentDictionary; + private ImmutableDictionary _immutableDictionary; + private ImmutableSortedDictionary _immutableSortedDictionary; [Params(Utils.DefaultCollectionSize)] public int Size; @@ -33,11 +33,11 @@ public void Setup() _found = UniqueValuesGenerator.GenerateArray(Size); _source = _found.ToDictionary(item => item, item => (TValue)(object)item); _dictionary = new Dictionary(_source); - _sortedlist = new SortedList(_source); - _sorteddictionary = new SortedDictionary(_source); - _concurrentdictionary = new ConcurrentDictionary(_source); - _immutabledictionary = Immutable.ImmutableDictionary.CreateRange(_source); - _immutablesorteddictionary = Immutable.ImmutableSortedDictionary.CreateRange(_source); + _sortedList = new SortedList(_source); + _sortedDictionary = new SortedDictionary(_source); + _concurrentDictionary = new ConcurrentDictionary(_source); + _immutableDictionary = Immutable.ImmutableDictionary.CreateRange(_source); + _immutableSortedDictionary = Immutable.ImmutableSortedDictionary.CreateRange(_source); } [Benchmark] @@ -47,7 +47,7 @@ public bool Dictionary() var collection = _dictionary; var found = _found; for (int i = 0; i < found.Length; i++) - result = collection.ContainsKey(found[i]); + result ^= collection.ContainsKey(found[i]); return result; } @@ -61,7 +61,7 @@ public bool ContainsKey(IDictionary collection) bool result = default; var found = _found; for (int i = 0; i < found.Length; i++) - result = collection.ContainsKey(found[i]); + result ^= collection.ContainsKey(found[i]); return result; } @@ -69,10 +69,10 @@ public bool ContainsKey(IDictionary collection) public bool SortedList() { bool result = default; - var collection = _sortedlist; + var collection = _sortedList; var found = _found; for (int i = 0; i < found.Length; i++) - result = collection.ContainsKey(found[i]); + result ^= collection.ContainsKey(found[i]); return result; } @@ -80,10 +80,10 @@ public bool SortedList() public bool SortedDictionary() { bool result = default; - var collection = _sorteddictionary; + var collection = _sortedDictionary; var found = _found; for (int i = 0; i < found.Length; i++) - result = collection.ContainsKey(found[i]); + result ^= collection.ContainsKey(found[i]); return result; } @@ -91,10 +91,10 @@ public bool SortedDictionary() public bool ConcurrentDictionary() { bool result = default; - var collection = _concurrentdictionary; + var collection = _concurrentDictionary; var found = _found; for (int i = 0; i < found.Length; i++) - result = collection.ContainsKey(found[i]); + result ^= collection.ContainsKey(found[i]); return result; } @@ -102,10 +102,10 @@ public bool ConcurrentDictionary() public bool ImmutableDictionary() { bool result = default; - var collection = _immutabledictionary; + var collection = _immutableDictionary; var found = _found; for (int i = 0; i < found.Length; i++) - result = collection.ContainsKey(found[i]); + result ^= collection.ContainsKey(found[i]); return result; } @@ -113,10 +113,10 @@ public bool ImmutableDictionary() public bool ImmutableSortedDictionary() { bool result = default; - var collection = _immutablesorteddictionary; + var collection = _immutableSortedDictionary; var found = _found; for (int i = 0; i < found.Length; i++) - result = collection.ContainsKey(found[i]); + result ^= collection.ContainsKey(found[i]); return result; } } diff --git a/src/benchmarks/corefx/System.Collections/Contains/ContainsTrue.cs b/src/benchmarks/corefx/System.Collections/Contains/ContainsTrue.cs index 329a8ed0dcc..53bd8dd1f21 100644 --- a/src/benchmarks/corefx/System.Collections/Contains/ContainsTrue.cs +++ b/src/benchmarks/corefx/System.Collections/Contains/ContainsTrue.cs @@ -17,15 +17,15 @@ public class ContainsTrue private T[] _array; private List _list; - private LinkedList _linkedlist; - private HashSet _hashset; + private LinkedList _linkedList; + private HashSet _hashSet; private Queue _queue; private Stack _stack; - private SortedSet _sortedset; - private ImmutableArray _immutablearray; - private ImmutableHashSet _immutablehashset; - private ImmutableList _immutablelist; - private ImmutableSortedSet _immutablesortedset; + private SortedSet _sortedSet; + private ImmutableArray _immutableArray; + private ImmutableHashSet _immutableHashSet; + private ImmutableList _immutableList; + private ImmutableSortedSet _immutableSortedSet; [Params(Utils.DefaultCollectionSize)] public int Size; @@ -36,15 +36,15 @@ public void Setup() _found = UniqueValuesGenerator.GenerateArray(Size); _array = _found.ToArray(); _list = new List(_found); - _linkedlist = new LinkedList(_found); - _hashset = new HashSet(_found); + _linkedList = new LinkedList(_found); + _hashSet = new HashSet(_found); _queue = new Queue(_found); _stack = new Stack(_found); - _sortedset = new SortedSet(_found); - _immutablearray = Immutable.ImmutableArray.CreateRange(_found); - _immutablehashset = Immutable.ImmutableHashSet.CreateRange(_found); - _immutablelist = Immutable.ImmutableList.CreateRange(_found); - _immutablesortedset = Immutable.ImmutableSortedSet.CreateRange(_found); + _sortedSet = new SortedSet(_found); + _immutableArray = Immutable.ImmutableArray.CreateRange(_found); + _immutableHashSet = Immutable.ImmutableHashSet.CreateRange(_found); + _immutableList = Immutable.ImmutableList.CreateRange(_found); + _immutableSortedSet = Immutable.ImmutableSortedSet.CreateRange(_found); } [Benchmark] @@ -54,7 +54,7 @@ public bool Array() var collection = _array; var found = _found; for (int i = 0; i < found.Length; i++) - result = collection.Contains(found[i]); + result ^= collection.Contains(found[i]); return result; } @@ -65,7 +65,7 @@ public bool List() var collection = _list; var found = _found; for (int i = 0; i < found.Length; i++) - result = collection.Contains(found[i]); + result ^= collection.Contains(found[i]); return result; } @@ -79,7 +79,7 @@ private bool Contains(ICollection collection) bool result = default; var found = _found; for (int i = 0; i < found.Length; i++) - result = collection.Contains(found[i]); + result ^= collection.Contains(found[i]); return result; } @@ -87,10 +87,10 @@ private bool Contains(ICollection collection) public bool LinkedList() { bool result = default; - var collection = _linkedlist; + var collection = _linkedList; var found = _found; for (int i = 0; i < found.Length; i++) - result = collection.Contains(found[i]); + result ^= collection.Contains(found[i]); return result; } @@ -98,10 +98,10 @@ public bool LinkedList() public bool HashSet() { bool result = default; - var collection = _hashset; + var collection = _hashSet; var found = _found; for (int i = 0; i < found.Length; i++) - result = collection.Contains(found[i]); + result ^= collection.Contains(found[i]); return result; } @@ -112,7 +112,7 @@ public bool Queue() var collection = _queue; var found = _found; for (int i = 0; i < found.Length; i++) - result = collection.Contains(found[i]); + result ^= collection.Contains(found[i]); return result; } @@ -123,7 +123,7 @@ public bool Stack() var collection = _stack; var found = _found; for (int i = 0; i < found.Length; i++) - result = collection.Contains(found[i]); + result ^= collection.Contains(found[i]); return result; } @@ -131,10 +131,10 @@ public bool Stack() public bool SortedSet() { bool result = default; - var collection = _sortedset; + var collection = _sortedSet; var found = _found; for (int i = 0; i < found.Length; i++) - result = collection.Contains(found[i]); + result ^= collection.Contains(found[i]); return result; } @@ -142,10 +142,10 @@ public bool SortedSet() public bool ImmutableArray() { bool result = default; - var collection = _immutablearray; + var collection = _immutableArray; var found = _found; for (int i = 0; i < found.Length; i++) - result = collection.Contains(found[i]); + result ^= collection.Contains(found[i]); return result; } @@ -153,10 +153,10 @@ public bool ImmutableArray() public bool ImmutableHashSet() { bool result = default; - var collection = _immutablehashset; + var collection = _immutableHashSet; var found = _found; for (int i = 0; i < found.Length; i++) - result = collection.Contains(found[i]); + result ^= collection.Contains(found[i]); return result; } @@ -164,10 +164,10 @@ public bool ImmutableHashSet() public bool ImmutableList() { bool result = default; - var collection = _immutablelist; + var collection = _immutableList; var found = _found; for (int i = 0; i < found.Length; i++) - result = collection.Contains(found[i]); + result ^= collection.Contains(found[i]); return result; } @@ -175,10 +175,10 @@ public bool ImmutableList() public bool ImmutableSortedSet() { bool result = default; - var collection = _immutablesortedset; + var collection = _immutableSortedSet; var found = _found; for (int i = 0; i < found.Length; i++) - result = collection.Contains(found[i]); + result ^= collection.Contains(found[i]); return result; } } diff --git a/src/benchmarks/corefx/System.Collections/Create/CtorDefaultSize.cs b/src/benchmarks/corefx/System.Collections/Create/CtorDefaultSize.cs index 30f4a9f8fef..7eac19890d5 100644 --- a/src/benchmarks/corefx/System.Collections/Create/CtorDefaultSize.cs +++ b/src/benchmarks/corefx/System.Collections/Create/CtorDefaultSize.cs @@ -11,7 +11,7 @@ namespace System.Collections [GenericTypeArguments(typeof(string))] // reference type public class CtorDefaultSize { - [Benchmark] + [Benchmark] // we keep this benchmark to compare the cost of creating array vs cost of array wrappers (List, Queue, Stack) public T[] Array() => new T[4]; // array has no default size, List has = 4 so I decided to use 4 here [Benchmark]