diff --git a/src/Directory.Build.props b/src/Directory.Build.props index da9467d..9aa6a2a 100644 --- a/src/Directory.Build.props +++ b/src/Directory.Build.props @@ -1,6 +1,6 @@ - 0.1.9 + 0.1.10 Tony Redondo, Grégory Léocadie net6.0;net7.0;net8.0 enable diff --git a/src/TimeItSharp.Common/Exporters/ConsoleExporter.cs b/src/TimeItSharp.Common/Exporters/ConsoleExporter.cs index 378b4cf..e1f1b2e 100644 --- a/src/TimeItSharp.Common/Exporters/ConsoleExporter.cs +++ b/src/TimeItSharp.Common/Exporters/ConsoleExporter.cs @@ -173,13 +173,23 @@ public void Export(TimeitResult results) for (var i = 0; i < totalNum; i++) { var item = orderedMetricsData[i]; - var itemResult = Utils.RemoveOutliers(item.Value, 3).ToList(); - int? outliersCount = item.Value.Count - itemResult.Count; - if (outliersCount > (_options.Configuration.Count * 5) / 100) + var itemResult = new List(); + var metricsOutliers = new List(); + var metricsThreshold = 0.5d; + while (metricsThreshold < 3.0d) { - itemResult = item.Value; - outliersCount = null; + itemResult = Utils.RemoveOutliers(item.Value, metricsThreshold).ToList(); + metricsOutliers = item.Value.Where(d => !itemResult.Contains(d)).ToList(); + var outliersPercent = ((double)metricsOutliers.Count / item.Value.Count) * 100; + if (outliersPercent < 20) + { + // outliers must be not more than 20% of the data + break; + } + + metricsThreshold += 0.1; } + var mMean = itemResult.Mean(); var mMedian = itemResult.Median(); @@ -211,7 +221,7 @@ public void Export(TimeitResult results) Math.Round(mMax, 6).ToString(), Math.Round(mP95, 6).ToString(), Math.Round(mP90, 6).ToString(), - outliersCount?.ToString() ?? "N/A"); + (metricsOutliers.Count == 0 ? "0" : metricsOutliers.Count + " {" + Math.Round(metricsThreshold, 2) + "}")); } } else diff --git a/src/TimeItSharp.Common/ScenarioProcessor.cs b/src/TimeItSharp.Common/ScenarioProcessor.cs index b5f4d1b..8a9912a 100644 --- a/src/TimeItSharp.Common/ScenarioProcessor.cs +++ b/src/TimeItSharp.Common/ScenarioProcessor.cs @@ -250,12 +250,12 @@ public void CleanScenario(Scenario scenario) } // Get outliers - List newDurations = new List(); - List outliers = new List(); + var newDurations = new List(); + var outliers = new List(); var threshold = 0.5d; var peakCount = 0; - int[] histogram = Array.Empty(); - Range[] labels = Array.Empty>(); + var histogram = Array.Empty(); + var labels = Array.Empty>(); var isBimodal = false; while (threshold < 2.0d) { @@ -287,7 +287,23 @@ public void CleanScenario(Scenario scenario) foreach (var key in metricsData.Keys) { var originalMetricsValue = metricsData[key]; - var metricsValue = Utils.RemoveOutliers(originalMetricsValue, 3).ToList(); + var metricsValue = new List(); + var metricsOutliers = new List(); + var metricsThreshold = 0.5d; + while (metricsThreshold < 3.0d) + { + metricsValue = Utils.RemoveOutliers(originalMetricsValue, metricsThreshold).ToList(); + metricsOutliers = originalMetricsValue.Where(d => !metricsValue.Contains(d)).ToList(); + var outliersPercent = ((double)metricsOutliers.Count / originalMetricsValue.Count) * 100; + if (outliersPercent < 20) + { + // outliers must be not more than 20% of the data + break; + } + + metricsThreshold += 0.1; + } + metricsData[key] = metricsValue; var mMean = metricsValue.Mean(); var mMedian = metricsValue.Median(); @@ -309,7 +325,8 @@ public void CleanScenario(Scenario scenario) metricsStats[key + ".p99"] = mP99; metricsStats[key + ".p95"] = mP95; metricsStats[key + ".p90"] = mP90; - metricsStats[key + ".outliers"] = originalMetricsValue.Count - metricsValue.Count; + metricsStats[key + ".outliers"] = metricsOutliers.Count; + metricsStats[key + ".outliers_threshold"] = metricsThreshold; } var assertResponse = ScenarioAssertion(dataPoints); diff --git a/src/TimeItSharp.Common/Utils.cs b/src/TimeItSharp.Common/Utils.cs index d982c15..a9e9ca6 100644 --- a/src/TimeItSharp.Common/Utils.cs +++ b/src/TimeItSharp.Common/Utils.cs @@ -234,7 +234,7 @@ public static double[][] GetComparisonTableData(IReadOnlyList re /// /// The default value to return if the width cannot be determined. Default is 180. /// The width of the console buffer, or the default value if it cannot be determined. - public static int GetSafeWidth(int defaultValue = 200) + public static int GetSafeWidth(int defaultValue = 260) { try {