So after running some test of my own it looks like Hash-Dictionary always wins. That is a Dictionary object with a HashCode, int32, as a key
10 items 500,000 itterations
Test Name First Last Not Found Average
FindInList 104.26 255.29 254.63 204.73
FindInArray 51.28 192.23 182.91 142.14
FindInHashDict 56.3 54.38 51.16 53.95
FindInDict 105.75 101.38 52.02 86.38
100 items 500,000 itterations
Test Name First Last Not Found Average
FindInList 102.83 1873.45 1820.85 1265.71
FindInArray 56.21 1313.61 1310.65 893.49
FindInHashDict 91.01 53.31 60.46 68.26
FindInDict 119.01 101.65 100.11 106.92
Here is my code that performs the find operation. My objects are hierarchical task that would be searched by a unique name. I know it is a long post but in case someone wanted to dispute the findings they can see the code.
private SearchResult FindInDict()
{
SearchResult result = new SearchResult();
result.SeachType = "FindInDict";
result.itterations = 1;
Stopwatch timer = new Stopwatch();
timer.Start();
if (dictStrBoundryTask.ContainsKey(NameOfFirst))
{
TaskBase t = dictStrBoundryTask[NameOfFirst];
}
timer.Stop();
result.firstItem = timer.Elapsed.TotalMilliseconds;
timer.Reset();
timer.Start();
if (dictStrBoundryTask.ContainsKey(NameOfLast))
{
TaskBase t = dictStrBoundryTask[NameOfLast];
}
timer.Stop();
result.lastItem = timer.Elapsed.TotalMilliseconds;
timer.Reset();
timer.Start();
if (dictStrBoundryTask.ContainsKey(NameOfNotFound))
{
TaskBase t = dictStrBoundryTask[NameOfNotFound];
}
timer.Stop();
result.notFoundItem = timer.Elapsed.TotalMilliseconds;
return result;
}
private SearchResult FindInHashDict()
{
SearchResult result = new SearchResult();
result.SeachType = "FindInHashDict";
result.itterations = 1;
Stopwatch timer = new Stopwatch();
timer.Start();
if (dictIntBoundryTask.ContainsKey(NameOfFirst.GetHashCode()))
{
TaskBase t = dictIntBoundryTask[NameOfFirst.GetHashCode()];
}
timer.Stop();
result.firstItem = timer.Elapsed.TotalMilliseconds;
timer.Reset();
timer.Start();
if (dictIntBoundryTask.ContainsKey(NameOfLast.GetHashCode()))
{
TaskBase t = dictIntBoundryTask[NameOfLast.GetHashCode()];
}
timer.Stop();
result.lastItem = timer.Elapsed.TotalMilliseconds;
timer.Reset();
timer.Start();
if (dictIntBoundryTask.ContainsKey(NameOfNotFound.GetHashCode()))
{
TaskBase t = dictIntBoundryTask[NameOfNotFound.GetHashCode()];
}
timer.Stop();
result.notFoundItem = timer.Elapsed.TotalMilliseconds;
return result;
}
private SearchResult FindInArray()
{
SearchResult result = new SearchResult();
result.SeachType = "FindInArray";
result.itterations = 1;
Stopwatch timer = new Stopwatch();
timer.Start();
foreach (TaskBase t in arrayBoundaryTask)
{
if (t.Name == NameOfFirst)
{
break;
}
}
timer.Stop();
result.firstItem = timer.Elapsed.TotalMilliseconds;
timer.Reset();
timer.Start();
foreach (TaskBase t in arrayBoundaryTask)
{
if (t.Name == NameOfLast)
{
break;
}
}
timer.Stop();
result.lastItem = timer.Elapsed.TotalMilliseconds;
timer.Reset();
timer.Start();
foreach (TaskBase t in arrayBoundaryTask)
{
if (t.Name == NameOfNotFound)
{
break;
}
}
timer.Stop();
result.notFoundItem = timer.Elapsed.TotalMilliseconds;
return result;
}
private SearchResult FindInList()
{
SearchResult result = new SearchResult();
result.SeachType = "FindInList";
result.itterations = 1;
Stopwatch timer = new Stopwatch();
timer.Start();
TaskBase t = listBoundaryTask.Find(x => x.Name == NameOfFirst);
if (t!=null)
{
}
timer.Stop();
result.firstItem = timer.Elapsed.TotalMilliseconds;
timer.Reset();
timer.Start();
t = listBoundaryTask.Find(x => x.Name == NameOfLast);
if (t != null)
{
}
timer.Stop();
result.lastItem = timer.Elapsed.TotalMilliseconds;
timer.Reset();
timer.Start();
t = listBoundaryTask.Find(x => x.Name == NameOfNotFound);
if (t != null)
{
}
timer.Stop();
result.notFoundItem = timer.Elapsed.TotalMilliseconds;
return result;
}