Skip to content

Commit b3ba083

Browse files
authored
Make BaselineCustomColumn expose "GetValue" as a public API (#1387)
- Add ability to generate baseline columns based on custom metrics - Expose the existing GetValue method as public - Closes #1385
1 parent 1d63d66 commit b3ba083

File tree

6 files changed

+25
-9
lines changed

6 files changed

+25
-9
lines changed

build.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,4 +92,4 @@ fi
9292
###########################################################################
9393

9494
# Start Cake
95-
exec mono "$CAKE_EXE" build.cake --verbosity=$VERBOSITY --configuration=$CONFIGURATION --target=$TARGET $DRYRUN "${SCRIPT_ARGUMENTS[@]}"
95+
exec mono "$CAKE_EXE" build.cake --verbosity=$VERBOSITY --configuration=$CONFIGURATION --target=$TARGET $DRYRUN "${SCRIPT_ARGUMENTS[@]}"

src/BenchmarkDotNet/Columns/BaselineCustomColumn.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
using System.Collections.Generic;
12
using BenchmarkDotNet.Mathematics;
23
using BenchmarkDotNet.Reports;
34
using BenchmarkDotNet.Running;
5+
using JetBrains.Annotations;
46

57
namespace BenchmarkDotNet.Columns
68
{
@@ -19,12 +21,16 @@ public string GetValue(Summary summary, BenchmarkCase benchmarkCase)
1921
return "?";
2022

2123
var baselineStat = summary[baseline].ResultStatistics;
24+
var baselineMetrics = summary[baseline].Metrics;
2225
var currentStat = summary[benchmarkCase].ResultStatistics;
26+
var currentMetrics = summary[benchmarkCase].Metrics;
2327

24-
return GetValue(summary, benchmarkCase, baselineStat, currentStat, isBaseline);
28+
return GetValue(summary, benchmarkCase, baselineStat, baselineMetrics, currentStat, currentMetrics, isBaseline);
2529
}
2630

27-
internal abstract string GetValue(Summary summary, BenchmarkCase benchmarkCase, Statistics baseline, Statistics current, bool isBaseline);
31+
[PublicAPI]
32+
public abstract string GetValue(Summary summary, BenchmarkCase benchmarkCase, Statistics baseline, IReadOnlyDictionary<string, Metric> baselineMetrics,
33+
Statistics current, IReadOnlyDictionary<string, Metric> currentMetrics, bool isBaseline);
2834

2935
public bool IsAvailable(Summary summary) => summary.HasBaselines();
3036
public bool AlwaysShow => true;

src/BenchmarkDotNet/Columns/BaselineRatioColumn.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Collections.Generic;
23
using System.Linq;
34
using BenchmarkDotNet.Extensions;
45
using BenchmarkDotNet.Mathematics;
@@ -44,7 +45,8 @@ public override string ColumnName
4445
}
4546
}
4647

47-
internal override string GetValue(Summary summary, BenchmarkCase benchmarkCase, Statistics baseline, Statistics current, bool isBaseline)
48+
public override string GetValue(Summary summary, BenchmarkCase benchmarkCase, Statistics baseline, IReadOnlyDictionary<string, Metric> baselineMetrics,
49+
Statistics current, IReadOnlyDictionary<string, Metric> currentMetrics, bool isBaseline)
4850
{
4951
var ratio = GetRatioStatistics(current, baseline);
5052
if (ratio == null)

src/BenchmarkDotNet/Columns/BaselineScaledColumn.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Collections.Generic;
23
using System.Linq;
34
using BenchmarkDotNet.Extensions;
45
using BenchmarkDotNet.Mathematics;
@@ -41,7 +42,8 @@ public override string ColumnName
4142
}
4243
}
4344

44-
internal override string GetValue(Summary summary, BenchmarkCase benchmarkCase, Statistics baseline, Statistics current, bool isBaseline)
45+
public override string GetValue(Summary summary, BenchmarkCase benchmarkCase, Statistics baseline, IReadOnlyDictionary<string, Metric> baselineMetrics,
46+
Statistics current, IReadOnlyDictionary<string, Metric> currentMetrics, bool isBaseline)
4547
{
4648
double mean = isBaseline ? 1 : Statistics.DivMean(current, baseline);
4749

src/BenchmarkDotNet/Columns/StatisticalTestColumn.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Collections.Generic;
23
using System.Linq;
34
using BenchmarkDotNet.Mathematics;
45
using BenchmarkDotNet.Mathematics.StatisticalTesting;
@@ -26,7 +27,8 @@ public StatisticalTestColumn(StatisticalTestKind kind, Threshold threshold, bool
2627
public override string Id => nameof(StatisticalTestColumn) + "." + Kind + "." + Threshold + "." + (ShowPValues ? "WithDetails" : "WithoutDetails");
2728
public override string ColumnName => $"{Kind}({Threshold.ToString().Replace(" ", "")}){(ShowPValues ? "/p-values" : "")}";
2829

29-
internal override string GetValue(Summary summary, BenchmarkCase benchmarkCase, Statistics baseline, Statistics current, bool isBaseline)
30+
public override string GetValue(Summary summary, BenchmarkCase benchmarkCase, Statistics baseline, IReadOnlyDictionary<string, Metric> baselineMetrics,
31+
Statistics current, IReadOnlyDictionary<string, Metric> currentMetrics, bool isBaseline)
3032
{
3133
var x = baseline.OriginalValues.ToArray();
3234
var y = current.OriginalValues.ToArray();

tests/BenchmarkDotNet.Tests/Columns/StatisticalTestColumnTests.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
using System.Linq;
1+
using System.Collections.Generic;
2+
using System.Linq;
23
using BenchmarkDotNet.Columns;
34
using BenchmarkDotNet.Mathematics;
45
using BenchmarkDotNet.Mathematics.StatisticalTesting;
6+
using BenchmarkDotNet.Reports;
57
using Xunit;
68

79
namespace BenchmarkDotNet.Tests.Columns
@@ -59,8 +61,10 @@ private static void Compare(StatisticalTestKind statisticalTestKind, ThresholdUn
5961
{
6062
var sut = new StatisticalTestColumn(statisticalTestKind, Threshold.Create(thresholdUnit, thresholdValue));
6163

62-
Assert.Equal(expectedResult, sut.GetValue(null, null, new Statistics(baseline), new Statistics(current), isBaseline: true));
63-
Assert.Equal(expectedResult, sut.GetValue(null, null, new Statistics(baseline), new Statistics(current), isBaseline: false));
64+
var emptyMetrics = new Dictionary<string, Metric>();
65+
66+
Assert.Equal(expectedResult, sut.GetValue(null, null, new Statistics(baseline), emptyMetrics, new Statistics(current), emptyMetrics, isBaseline: true));
67+
Assert.Equal(expectedResult, sut.GetValue(null, null, new Statistics(baseline), emptyMetrics, new Statistics(current), emptyMetrics, isBaseline: false));
6468
}
6569
}
6670
}

0 commit comments

Comments
 (0)