I have an app that uses performance counters to get the cores/threads load and finding the highest value. Since there are 12/16/36 etc. threads normally in our days, I used a List and Math.Max to find the highest load.
However, the refresh interval is 100ms, so it must make calculations 600 times per minute and I want to optimize the code as much as possible, to be able to go with the even faster refresh rate.
What is the most efficient way to do that? I read the THREAD about it where people tested the efficiency, and while some say there is nearly no difference between Math.Max and for/while/if implementation, others say that when you work with doubles or float (which is what I have), the difference is huge, 0.3465041 sec for inline implementation and 6 sec for Math.Max.
So, what will be the best way to do the calculations in your opinion and how it can be done with a List? Thank you in advance! Here is what I use ATM:
private void maxThreadTimer_Tick(object sender, EventArgs e) //Max Thread Timer
{
float allCores1 = coreLoad1.NextValue();
float allCores2 = coreLoad2.NextValue();
float allCores3 = coreLoad3.NextValue();
float allCores4 = coreLoad4.NextValue();
float allCores5 = coreLoad5.NextValue();
float allCores6 = coreLoad6.NextValue();
float allCores7 = coreLoad7.NextValue();
float allCores8 = coreLoad8.NextValue();
float allCores9 = coreLoad9.NextValue();
float allCores10 = coreLoad10.NextValue();
float allCores11 = coreLoad11.NextValue();
float allCores12 = coreLoad12.NextValue();
float allCores13 = coreLoad13.NextValue();
float allCores14 = coreLoad14.NextValue();
float allCores15 = coreLoad15.NextValue();
float allCores16 = coreLoad16.NextValue();
List<float> valuesList = new List<float> { allCores1, allCores2,
allCores3, allCores4, allCores5, allCores6, allCores7, allCores8,
allCores9, allCores10, allCores11, allCores12, allCores13, allCores14,
allCores15, allCores16 };
float tMax = valuesList.Max();
}