To find a faster solution start a profile!
Measure how long it takes for every step in your for loop and try to avoid the biggest bottleneck.
After making a second look at your code, it seems, your problem is that you run six times over your big list. So the time needed is always six times of the list size.
Instead you should run once over the whole list and put every item into the correct slot.
Just to make a performance test for yourself you should test these two approaches:
Sample class to hold data
public class Coordinates
{
public double x1 { get; set; }
public double x2 { get; set; }
public double y1 { get; set; }
public double y2 { get; set; }
public double z1 { get; set; }
public double z2 { get; set; }
}
Initializing of the value holder
Coordinates minCoordinates = new Coordinates();
//Cause we want to hold the minimum value, it will be initialized with
//value that is definitely greater or equal than the greatest in the list
minCoordinates.x1 = Double.MaxValue;
minCoordinates.x2 = Double.MaxValue;
minCoordinates.y1 = Double.MaxValue;
minCoordinates.y2 = Double.MaxValue;
minCoordinates.z1 = Double.MaxValue;
minCoordinates.z2 = Double.MaxValue;
Using a for loop if the index operator is O(1)
for (int i = 0; i < allCoordinates.Count; i++)
{
switch (i % 6)
{
case 0:
minCoordinates.x1 = Math.Min(minCoordinates.x1, allCoordinates[i]);
break;
case 1:
minCoordinates.x2 = Math.Min(minCoordinates.x2, allCoordinates[i]);
break;
case 2:
minCoordinates.y1 = Math.Min(minCoordinates.y1, allCoordinates[i]);
break;
case 3:
minCoordinates.y2 = Math.Min(minCoordinates.y2, allCoordinates[i]);
break;
case 4:
minCoordinates.z1 = Math.Min(minCoordinates.z1, allCoordinates[i]);
break;
case 5:
minCoordinates.z2 = Math.Min(minCoordinates.z2, allCoordinates[i]);
break;
}
}
Using foreach if IEnumerator is O(1)
int count = 0;
foreach (var item in allCoordinates)
{
switch (count % 6)
{
case 0:
minCoordinates.x1 = Math.Min(minCoordinates.x1, item);
break;
case 1:
minCoordinates.x2 = Math.Min(minCoordinates.x2, item);
break;
case 2:
minCoordinates.y1 = Math.Min(minCoordinates.y1, item);
break;
case 3:
minCoordinates.y2 = Math.Min(minCoordinates.y2, item);
break;
case 4:
minCoordinates.z1 = Math.Min(minCoordinates.z1, item);
break;
case 5:
minCoordinates.z2 = Math.Min(minCoordinates.z2, item);
break;
}
count++;
}