in Microsoft.Shared.Dna.Json.Profile/Profiler.cs [63:96]
private static bool ExecuteGeneric<T>(int iterations, out double meanElapsedMilliseconds) where T : IProfile, new()
{
bool result = true;
int dop = Environment.ProcessorCount;
Thread[] executors = new Thread[dop];
ExecuteState[] states = new ExecuteState[dop];
int perExecutor = iterations / dop;
int remainder = iterations % dop;
for (int i = 0; i < dop; i++)
{
states[i] = new ExecuteState
{
Iterations = perExecutor + (--remainder > 0 ? 1 : 0),
Count = 0L,
Total = 0L,
Valid = true
};
executors[i] = new Thread(Profiler.ExecutePartial<T>);
executors[i].Start(states[i]);
}
long total = 0L;
long count = 0L;
for (int i = 0; i < dop; i++)
{
executors[i].Join();
total += states[i].Total;
count += states[i].Count;
result = result && states[i].Valid;
}
meanElapsedMilliseconds = (double)total / TimeSpan.TicksPerMillisecond / count;
return result;
}