>Going from an iterative approach to an equivalent LINQ approach is rarely going to improve speed, and it may even slow it down due to the overhead involved. It does however allow you to easily make it parallel by adding an AsParallel() after AsEnumerable(), which may improve the speed. I don't know if the data reader's GetFieldType method is thread-safe, so that may not be an option. You could also use the appropriate .Field< Type> instead of Convert if they are already the correct type.
>
>Of course you'll need to test if the LINQ statement is actually the slow part of your code.
By running Analysis I see this method to be slow (7.5%)
public static void PopulateFromSQML(this Dictionary<String, String> tDictionary, String tcSQML)
{
tDictionary.Clear();
String pattern = @"<(?<field>[^/>]+)>(?<data>.*)</\k<field>>";
MatchCollection matches = Regex.Matches(tcSQML, pattern, RegexOptions.Singleline);
foreach (Match m in matches)
{
if (!tDictionary.ContainsKey(m.Groups["field"].ToString()))
tDictionary.Add(m.Groups["field"].ToString(), m.Groups["data"].ToString().Trim());
}
}
And also one method where statements like
Byte originalPodBkType = bookingRow.Field<Byte>("podbktype");
take 1.9%
If it's not broken, fix it until it is.
My Blog