>>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%
First thing I would do would be to see if you can use XDocument (
http://msdn.microsoft.com/en-us/library/system.xml.linq.xdocument.aspx) or an XmlReader (
http://msdn.microsoft.com/en-us/library/system.xml.xmlreader.aspx) to read the data. Since the pattern indicates a form of XML, these might be faster.
If the XML classes don't work, then since your pattern doesn't change, create a static compiled Regex (
http://msdn.microsoft.com/en-us/library/system.text.regularexpressions.regexoptions.aspx). MatchCollection also implements IEnumerable, so you could potentially turn the foreach loop into a parallel LINQ query. If the field isn't distinct you may need to create your own IEqualityComparer (
http://msdn.microsoft.com/en-us/library/bb338049.aspx) to prevent errors if converting it straight into a dictionary .
As for getting the field values from the row, I don't see any way you can really improve that speed.