tags:

views:

31

answers:

1

I need to run a LINQ on a generic collection.
The current query runs at a really slow pace...

var patternsWithMaxLenArray = totalPatterns
    .Where
    (
        pattern => pattern.Contains(maxLen) &&
                   pattern.All(lenInPattern => curQuantities.Keys.Contains(lenInPattern)) &&
                   pattern.GroupBy(len => len).All(g => g.Count() <= curQuantities[g.Key])
    )
    .Select(pattern => new { pattern = pattern, sum = pattern.Sum() })
    .ToArray();

var patternsWithMaxLen = patternsWithMaxLenArray
    .OrderByDescending(patternsum => patternsum.sum)
    .Select(patternsum => patternsum.pattern);

var iq = patternsWithMaxLen.First();
+1  A: 

Measure Measure Measure. Strip everything out to the simplest query and measure it. Then add in bits at a time until you find 'the hole.'

n8wrl
Used a ANTS Profiler... helped a lot
Sam