PerfResult PrepareResult(string name, double[] times) { Array.Sort(times); int n = times.Length; var result = new PerfResult() { Name = name, Min = times[0], Max = times[n - 1] }; double total = 0; for (int i = 0; i < n; i++) { total += times[i]; } result.Mean = total / n; if (n == 1) { result.Median = times[0]; } else if (n % 2 == 1) { result.Median = times[n / 2]; } else { result.Median = (times[n / 2] + times[n / 2 - 1]) / 2; } return(result); }
void PrintResult(PerfResult result) { var sb = new StringBuilder(); sb.Append(textBox1.Text); sb.AppendLine(result.Name); sb.AppendLine($"Min: {result.Min:F3} ms"); sb.AppendLine($"Max: {result.Max:F3} ms"); sb.AppendLine($"Avg: {result.Mean:F3} ms"); sb.AppendLine($"Median: {result.Median:F3} ms"); textBox1.Text = sb.ToString(); }