I have a 2-dimensional array of objects (mainly, but not exclusively strings) that I want to filter by string ( sSearch) using LINQ. The following query works, but not as fast as we would like.
I changed Countto Any, which led to a significant increase in speed and replaced Containsby a regular expression that ignores the case, thereby eliminating the call ToLower. Combined, this reduced lead time in two parts.
What is now very noticeable is that an increase in the length of a search query from 1 to 2 letters will triple the execution time, and there is another jump from 3 to 4 letters (~ 50% increase in execution time). Although this, of course, is not surprising, I wonder if there is anything else that could be done to optimize string matching?
Regex rSearch = new Regex(sSearch, RegexOptions.IgnoreCase);
rawData.Where(row => row.Any(column => rSearch.IsMatch(column.ToString())));
In this case, the data set has about 10 thousand rows and 50 columns, but the size can vary significantly.
Any suggestions on optimizing this are welcome.
source
share