public ProfilerStatistics[] PerformAnalysis() { var dict = CreateDictionary(); var stats = dict.Select(kvp => ProfilerStatistics.CalculateStatistics(kvp.Key, kvp.Value)); return(stats.ToArray()); }
public static ProfilerStatistics CalculateStatistics(int code, List <TimeSpan> times) { var result = new ProfilerStatistics(code, times.ToArray()); var mean = times.Average(t => t.Ticks); double variance = 0; for (int i = 0; i < times.Count; i++) { variance += ((times[i].Ticks - mean) * (times[i].Ticks - mean)) / times.Count; } var stdDev = Math.Sqrt(variance); result.TotalTime = new TimeSpan(times.Sum(ts => ts.Ticks)); result.Mean = new TimeSpan((long)mean); result.Min = times.Min(); result.Max = times.Max(); result.StandardDeviation = new TimeSpan((long)stdDev); return(result); }