Skip to content

Commit

Permalink
code review fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
adamsitnik committed Jul 19, 2018
1 parent 229c5e6 commit d734b8e
Show file tree
Hide file tree
Showing 6 changed files with 115 additions and 113 deletions.
6 changes: 4 additions & 2 deletions src/benchmarks/corefx/Common/UniqueValuesGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T>(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<T>();

Expand All @@ -25,7 +27,7 @@ internal static T[] GenerateArray<T>(int count)

internal static Dictionary<TKey, TValue> GenerateDictionary<TKey, TValue>(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<TKey, TValue>();

Expand Down
66 changes: 33 additions & 33 deletions src/benchmarks/corefx/System.Collections/Contains/ContainsFalse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ public class ContainsFalse<T>

private T[] _array;
private List<T> _list;
private LinkedList<T> _linkedlist;
private HashSet<T> _hashset;
private LinkedList<T> _linkedList;
private HashSet<T> _hashSet;
private Queue<T> _queue;
private Stack<T> _stack;
private SortedSet<T> _sortedset;
private ImmutableArray<T> _immutablearray;
private ImmutableHashSet<T> _immutablehashset;
private ImmutableList<T> _immutablelist;
private ImmutableSortedSet<T> _immutablesortedset;
private SortedSet<T> _sortedSet;
private ImmutableArray<T> _immutableArray;
private ImmutableHashSet<T> _immutableHashSet;
private ImmutableList<T> _immutableList;
private ImmutableSortedSet<T> _immutableSortedSet;

[Params(Utils.DefaultCollectionSize)]
public int Size;
Expand All @@ -39,15 +39,15 @@ public void Setup()

_array = secondHalf;
_list = new List<T>(secondHalf);
_linkedlist = new LinkedList<T>(secondHalf);
_hashset = new HashSet<T>(secondHalf);
_linkedList = new LinkedList<T>(secondHalf);
_hashSet = new HashSet<T>(secondHalf);
_queue = new Queue<T>(secondHalf);
_stack = new Stack<T>(secondHalf);
_sortedset = new SortedSet<T>(secondHalf);
_immutablearray = Immutable.ImmutableArray.CreateRange<T>(secondHalf);
_immutablehashset = Immutable.ImmutableHashSet.CreateRange<T>(secondHalf);
_immutablelist = Immutable.ImmutableList.CreateRange<T>(secondHalf);
_immutablesortedset = Immutable.ImmutableSortedSet.CreateRange<T>(secondHalf);
_sortedSet = new SortedSet<T>(secondHalf);
_immutableArray = Immutable.ImmutableArray.CreateRange<T>(secondHalf);
_immutableHashSet = Immutable.ImmutableHashSet.CreateRange<T>(secondHalf);
_immutableList = Immutable.ImmutableList.CreateRange<T>(secondHalf);
_immutableSortedSet = Immutable.ImmutableSortedSet.CreateRange<T>(secondHalf);
}

[Benchmark]
Expand All @@ -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;
}

Expand All @@ -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;
}

Expand All @@ -82,29 +82,29 @@ private bool Contains(ICollection<T> 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;
}

[Benchmark]
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;
}

[Benchmark]
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;
}

Expand All @@ -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;
}

Expand All @@ -126,62 +126,62 @@ 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;
}

[Benchmark]
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;
}

[Benchmark]
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;
}

[Benchmark]
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;
}

[Benchmark]
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;
}

[Benchmark]
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;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ public class ContainsKeyFalse<TKey, TValue>
private Dictionary<TKey, TValue> _source;

private Dictionary<TKey, TValue> _dictionary;
private SortedList<TKey, TValue> _sortedlist;
private SortedDictionary<TKey, TValue> _sorteddictionary;
private ConcurrentDictionary<TKey, TValue> _concurrentdictionary;
private ImmutableDictionary<TKey, TValue> _immutabledictionary;
private ImmutableSortedDictionary<TKey, TValue> _immutablesorteddictionary;
private SortedList<TKey, TValue> _sortedList;
private SortedDictionary<TKey, TValue> _sortedDictionary;
private ConcurrentDictionary<TKey, TValue> _concurrentDictionary;
private ImmutableDictionary<TKey, TValue> _immutableDictionary;
private ImmutableSortedDictionary<TKey, TValue> _immutableSortedDictionary;

[Params(Utils.DefaultCollectionSize)]
public int Size;
Expand All @@ -35,11 +35,11 @@ public void Setup()

_source = values.Skip(Size).Take(Size).ToDictionary(item => item, item => (TValue)(object)item);
_dictionary = new Dictionary<TKey, TValue>(_source);
_sortedlist = new SortedList<TKey, TValue>(_source);
_sorteddictionary = new SortedDictionary<TKey, TValue>(_source);
_concurrentdictionary = new ConcurrentDictionary<TKey, TValue>(_source);
_immutabledictionary = Immutable.ImmutableDictionary.CreateRange<TKey, TValue>(_source);
_immutablesorteddictionary = Immutable.ImmutableSortedDictionary.CreateRange<TKey, TValue>(_source);
_sortedList = new SortedList<TKey, TValue>(_source);
_sortedDictionary = new SortedDictionary<TKey, TValue>(_source);
_concurrentDictionary = new ConcurrentDictionary<TKey, TValue>(_source);
_immutableDictionary = Immutable.ImmutableDictionary.CreateRange<TKey, TValue>(_source);
_immutableSortedDictionary = Immutable.ImmutableSortedDictionary.CreateRange<TKey, TValue>(_source);
}

[Benchmark]
Expand All @@ -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;
}

Expand All @@ -63,62 +63,62 @@ public bool ContainsKey(IDictionary<TKey, TValue> 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;
}

[Benchmark]
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;
}

[Benchmark]
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;
}

[Benchmark]
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;
}

[Benchmark]
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;
}

[Benchmark]
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;
}
}
Expand Down
Loading

0 comments on commit d734b8e

Please sign in to comment.