Skip to content

Commit 7a1c10d

Browse files
Fix bugs in statistical tests, fix #2542
1 parent ad0240c commit 7a1c10d

File tree

4 files changed

+14
-9
lines changed

4 files changed

+14
-9
lines changed

samples/BenchmarkDotNet.Samples/IntroStatisticalTesting.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
namespace BenchmarkDotNet.Samples
55
{
6-
[StatisticalTestColumn("1us")]
6+
[StatisticalTestColumn("500us")]
77
[StatisticalTestColumn("3%")]
88
[SimpleJob(warmupCount: 0, iterationCount: 5)]
99
public class IntroStatisticalTesting

src/BenchmarkDotNet/Analysers/ZeroMeasurementHelper.cs

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using BenchmarkDotNet.Mathematics;
22
using Perfolizer;
3+
using Perfolizer.Horology;
34
using Perfolizer.Mathematics.Common;
45
using Perfolizer.Mathematics.GenericEstimators;
56
using Perfolizer.Mathematics.SignificanceTesting;
@@ -13,8 +14,12 @@ internal static class ZeroMeasurementHelper
1314
public static bool IsNegligible(Sample results, double threshold) => HodgesLehmannEstimator.Instance.Median(results) < threshold;
1415
public static bool IsNoticeable(Sample results, double threshold) => !IsNegligible(results, threshold);
1516

16-
public static bool AreIndistinguishable(double[] workload, double[] overhead, Threshold? threshold = null) =>
17-
AreIndistinguishable(new Sample(workload), new Sample(overhead), threshold);
17+
public static bool AreIndistinguishable(double[] workload, double[] overhead, Threshold? threshold = null)
18+
{
19+
var workloadSample = new Sample(workload, TimeUnit.Nanosecond);
20+
var overheadSample = new Sample(overhead, TimeUnit.Nanosecond);
21+
return AreIndistinguishable(workloadSample, overheadSample, threshold);
22+
}
1823

1924
public static bool AreIndistinguishable(Sample workload, Sample overhead, Threshold? threshold = null)
2025
{

src/BenchmarkDotNet/Columns/StatisticalTestColumn.cs

+4-5
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,12 @@ public override string GetValue(Summary summary, BenchmarkCase benchmarkCase, St
3636
Statistics current, IReadOnlyDictionary<string, Metric> currentMetrics, bool isBaseline)
3737
{
3838
if (baseline.Sample.Values.SequenceEqual(current.Sample.Values))
39-
return "Base";
39+
return "Baseline";
4040
if (current.Sample.Size == 1 && baseline.Sample.Size == 1)
4141
return "?";
4242

43-
var tost = new SimpleEquivalenceTest(MannWhitneyTest.Instance);
44-
var comparisonResult = tost.Perform(current.Sample, baseline.Sample, Threshold, SignificanceLevel);
43+
var test = new SimpleEquivalenceTest(MannWhitneyTest.Instance);
44+
var comparisonResult = test.Perform(current.Sample, baseline.Sample, Threshold, SignificanceLevel);
4545
return comparisonResult switch
4646
{
4747
ComparisonResult.Greater => "Slower",
@@ -55,7 +55,6 @@ public override string GetValue(Summary summary, BenchmarkCase benchmarkCase, St
5555
public override bool IsNumeric => false;
5656
public override UnitType UnitType => UnitType.Dimensionless;
5757

58-
public override string Legend =>
59-
$"MannWhitney-based TOST equivalence test (threshold={Threshold}, alpha = {SignificanceLevel}";
58+
public override string Legend => $"MannWhitney-based equivalence test (threshold={Threshold}, alpha = {SignificanceLevel})";
6059
}
6160
}

src/BenchmarkDotNet/Mathematics/Statistics.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using BenchmarkDotNet.Extensions;
55
using JetBrains.Annotations;
66
using Perfolizer;
7+
using Perfolizer.Horology;
78
using Perfolizer.Mathematics.Common;
89
using Perfolizer.Mathematics.OutlierDetection;
910
using Perfolizer.Mathematics.QuantileEstimators;
@@ -45,7 +46,7 @@ public Statistics(params double[] values) :
4546
public Statistics(IEnumerable<int> values) :
4647
this(values.Select(value => (double)value)) { }
4748

48-
public Statistics(IEnumerable<double> values) : this(new Sample(values.ToArray())) { }
49+
public Statistics(IEnumerable<double> values) : this(new Sample(values.ToArray(), TimeUnit.Nanosecond)) { }
4950

5051
public Statistics(Sample sample)
5152
{

0 commit comments

Comments
 (0)