Optimise nested loops used to compare champions which have abilities which have effects I'm creating a counter picker for a game called League of Legends, and for this I need to compare effects of abilities, which each champion has. For this I'm using 4 lists of champions, the returnList, the banned champion list, the enemy champions list, annd the allied champion lists. 

However, seeing that the returnlist, where the champions get there points, contains around 120 instances, which all have 5 abilities, which in turn have around 5 effects each, I feel that my current solution of nesting foreach loops might be really slow. 

I was wondering how I could best optimise this

foreach (CounterChampion champion1 in enemyList)
{
    foreach (CounterAbility ability1 in champion1.Abilities)
    {
        foreach (string effects1 in ability1.Effects)
        {
            foreach (CounterChampion champion2 in returnList)
            {
                foreach (string effects2 in champion2.Abilities.SelectMany(ability2 =&gt; ability2.Effects))
                {
                    if (CounterEffectExists(effects2, effects1, CounterEffect.EffectType.Counters))
                    {
                        champion2.AddPoints(1);
                    }
                    if (CounterEffectExists(effects1, effects2, CounterEffect.EffectType.Counters))
                    {
                        champion2.AddPoints(-1);
                    }
                }
            }
        }
    }
}
foreach (CounterChampion champion1 in banList)
{
    foreach (CounterAbility ability1 in champion1.Abilities)
    {
        foreach (string effects1 in ability1.Effects)
        {
            foreach (CounterChampion champion2 in returnList)
            {
                foreach (string effects2 in champion2.Abilities.SelectMany(ability2 =&gt; ability2.Effects))
                {
                    if (CounterEffectExists(effects1, effects2, CounterEffect.EffectType.Counters))
                    {
                        champion2.AddPoints(1);
                    }
                }
            }
        }
    }
}
foreach (CounterChampion champion1 in allyList)
{
    foreach (CounterAbility ability1 in champion1.Abilities)
    {
        foreach (string effects1 in ability1.Effects)
        {
            foreach (CounterChampion champion2 in returnList)
            {
                foreach (string effects2 in champion2.Abilities.SelectMany(ability2 =&gt; ability2.Effects))
                {
                    if (CounterEffectExists(effects2, effects1, CounterEffect.EffectType.WorksWith))
                    {
                        champion2.AddPoints(1);
                    }
                    if (CounterEffectExists(effects1, effects2, CounterEffect.EffectType.WorksWith))
                    {
                        champion2.AddPoints(1);
                    }
                }
            }
        }
    }
}
returnList.Sort(
    delegate (CounterChampion c1,
    CounterChampion c2)
    {
        return c1.GetPoints().CompareTo(c2.GetPoints()) * -1;
    }
);
return returnList;
Well the inner loop is something like 120*5*5 => 1200 cycles and I really don't know if it can become an issue with today's PC power. But improvements can always be made, and reading your code, I see that some lines are duplicated :

   foreach (CounterChampion champion2 in returnList)
    {
        foreach (string effects2 in champion2.Abilities.SelectMany(ability2 =&gt; ability2.Effects))
        {


As as first step toward performance and code structuration, I suggest to compute the ability/effect in returnList once, and reuse it after. Typically, you may have something like this :

class EffectByChampion{
  CounterChampion Champion,
  List&lt;string&gt; Effects
}


then you may fill the following list ONCE

List&lt;EffectByChampion&gt;


and after you may reuse it 3 times through your existing code with :

    foreach (string effects1 in ability1.Effects)
    {
      foreach(EffectByChampion effectByChampion in EffectByChampionList)
      {
       foreach(string effects2 in effectByChampion)


This way, you have 3 foreach loops removed. 
Hope this help !