Skip to content

Commit d3d5e4e

Browse files
Migrate to Pragmastat via Perfolizer 0.6.0
1 parent 4a3b19c commit d3d5e4e

File tree

14 files changed

+49
-19
lines changed

14 files changed

+49
-19
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727

2828
**BenchmarkDotNet** helps you to transform methods into benchmarks, track their performance, and share reproducible measurement experiments.
2929
It's no harder than writing unit tests!
30-
Under the hood, it performs a lot of [magic](#automation) that guarantees [reliable and precise](#reliability) results thanks to the [perfolizer](https://github.com/AndreyAkinshin/perfolizer) statistical engine.
30+
Under the hood, it performs a lot of [magic](#automation) that guarantees [reliable and precise](#reliability) results thanks to the [perfolizer](https://github.com/AndreyAkinshin/perfolizer) and [pragmastat](https://github.com/AndreyAkinshin/pragmastat) statistical engine.
3131
BenchmarkDotNet protects you from popular benchmarking mistakes and warns you if something is wrong with your benchmark design or obtained measurements.
3232
The results are presented in a [user-friendly](#friendliness) form that highlights all the important facts about your experiment.
3333
BenchmarkDotNet is already adopted by [27200+ GitHub projects](https://github.com/dotnet/BenchmarkDotNet/network/dependents) including

src/BenchmarkDotNet.Diagnostics.Windows/Tracing/NativeMemoryLogParser.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -247,13 +247,19 @@ bool IsCallStackIn(StackSourceCallStackIndex index)
247247
var memoryLeakPerOperation = nativeLeakSize / totalOperation;
248248

249249
logger.WriteLine(
250-
$"Native memory allocated per single operation: {SizeValue.FromBytes(memoryAllocatedPerOperation).ToString(SizeUnit.B, null, benchmarkCase.Config.CultureInfo)}");
250+
$"Native memory allocated per single operation: " +
251+
$"{PerfolizerMeasurementFormatter.Instance.Format(
252+
SizeValue.FromBytes(memoryAllocatedPerOperation).ToMeasurement(SizeUnit.B),
253+
formatProvider: benchmarkCase.Config.CultureInfo)}");
251254
logger.WriteLine($"Count of allocated object: {countOfAllocatedObject / totalOperation}");
252255

253256
if (nativeLeakSize != 0)
254257
{
255258
logger.WriteLine(
256-
$"Native memory leak per single operation: {SizeValue.FromBytes(memoryLeakPerOperation).ToString(SizeUnit.B, null, benchmarkCase.Config.CultureInfo)}");
259+
$"Native memory leak per single operation: " +
260+
$"{PerfolizerMeasurementFormatter.Instance.Format(
261+
SizeValue.FromBytes(memoryLeakPerOperation).ToMeasurement(SizeUnit.B),
262+
formatProvider: benchmarkCase.Config.CultureInfo)}");
257263
}
258264

259265
var heapInfoList = heaps.Select(h => new { Address = h.Key, h.Value.Count, types = h.Value.Values });

src/BenchmarkDotNet/Analysers/ZeroMeasurementHelper.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@
66
using Perfolizer.Mathematics.SignificanceTesting;
77
using Perfolizer.Mathematics.SignificanceTesting.MannWhitney;
88
using Perfolizer.Metrology;
9+
using Pragmastat;
10+
using Pragmastat.Estimators;
911

1012
namespace BenchmarkDotNet.Analysers
1113
{
1214
internal static class ZeroMeasurementHelper
1315
{
14-
public static bool IsNegligible(Sample results, double threshold) => HodgesLehmannEstimator.Instance.Median(results) < threshold;
16+
public static bool IsNegligible(Sample results, double threshold) => CenterEstimator.Instance.Estimate(results) < threshold;
1517
public static bool IsNoticeable(Sample results, double threshold) => !IsNegligible(results, threshold);
1618

1719
public static bool AreIndistinguishable(double[] workload, double[] overhead, Threshold? threshold = null)

src/BenchmarkDotNet/BenchmarkDotNet.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
<PackageReference Include="Gee.External.Capstone" Version="2.3.0" />
2323
<PackageReference Include="Iced" Version="1.21.0" />
2424
<PackageReference Include="Microsoft.Diagnostics.Runtime" Version="3.1.512801" />
25-
<PackageReference Include="Perfolizer" Version="[0.5.4]" />
25+
<PackageReference Include="Perfolizer" Version="[0.6.0]" />
2626
<PackageReference Include="Microsoft.Diagnostics.Tracing.TraceEvent" Version="3.1.21" PrivateAssets="contentfiles;analyzers" />
2727
<PackageReference Include="Microsoft.DotNet.PlatformAbstractions" Version="3.1.6" />
2828
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.14.0" />

src/BenchmarkDotNet/Columns/MetricColumn.cs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using BenchmarkDotNet.Running;
55
using Perfolizer.Horology;
66
using Perfolizer.Metrology;
7+
using Pragmastat.Metrology;
78

89
namespace BenchmarkDotNet.Columns
910
{
@@ -48,14 +49,21 @@ public string GetValue(Summary summary, BenchmarkCase benchmarkCase, SummaryStyl
4849
string numberFormat = descriptor.NumberFormat;
4950

5051
if (printUnits && descriptor.UnitType == UnitType.CodeSize)
51-
return SizeValue.FromBytes((long)metric.Value).ToString(style.CodeSizeUnit, numberFormat, cultureInfo, unitPresentation);
52+
{
53+
var measurement = SizeValue.FromBytes((long)metric.Value).ToMeasurement(style.CodeSizeUnit);
54+
return PerfolizerMeasurementFormatter.Instance.Format(measurement, numberFormat, cultureInfo, unitPresentation);
55+
}
5256
if (printUnits && descriptor.UnitType == UnitType.Size)
53-
return SizeValue.FromBytes((long)metric.Value).ToString(style.SizeUnit, numberFormat, cultureInfo, unitPresentation);
57+
{
58+
var measurement = SizeValue.FromBytes((long)metric.Value).ToMeasurement(style.SizeUnit);
59+
return PerfolizerMeasurementFormatter.Instance.Format(measurement, numberFormat, cultureInfo, unitPresentation);
60+
}
5461
if (printUnits && descriptor.UnitType == UnitType.Time)
5562
{
5663
if (numberFormat.IsBlank())
5764
numberFormat = "N4";
58-
return TimeInterval.FromNanoseconds(metric.Value).ToString(style.TimeUnit, numberFormat, cultureInfo, unitPresentation);
65+
var measurement = TimeInterval.FromNanoseconds(metric.Value).ToMeasurement(style.TimeUnit);
66+
return PerfolizerMeasurementFormatter.Instance.Format(measurement, numberFormat, cultureInfo, unitPresentation);
5967
}
6068

6169
return metric.Value.ToString(numberFormat, cultureInfo);

src/BenchmarkDotNet/Columns/StatisticColumn.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
using Perfolizer.Mathematics.Common;
1111
using Perfolizer.Mathematics.Multimodality;
1212
using Perfolizer.Metrology;
13+
using Pragmastat.Metrology;
1314

1415
namespace BenchmarkDotNet.Columns
1516
{
@@ -153,12 +154,11 @@ private string Format(Summary summary, ImmutableConfig config, Statistics? stati
153154
if (double.IsNaN(value))
154155
return "NA";
155156
return UnitType == UnitType.Time
156-
? TimeInterval.FromNanoseconds(value)
157-
.ToString(
158-
style.TimeUnit,
159-
format,
160-
style.CultureInfo,
161-
new UnitPresentation(style.PrintUnitsInContent, minUnitWidth: 0, gap: true))
157+
? PerfolizerMeasurementFormatter.Instance.Format(
158+
TimeInterval.FromNanoseconds(value).ToMeasurement(style.TimeUnit),
159+
format,
160+
style.CultureInfo,
161+
new UnitPresentation(style.PrintUnitsInContent, minUnitWidth: 0, gap: true))
162162
: value.ToString(format, style.CultureInfo);
163163
}
164164

src/BenchmarkDotNet/Environments/HostEnvironmentInfo.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,13 @@ public override IEnumerable<string> ToFormattedString()
9797
yield return Cpu.Value.ToFullBrandName();
9898
if (HardwareTimerKind != HardwareTimerKind.Unknown)
9999
{
100-
string frequency = ChronometerFrequency.ToString(FrequencyUnit.Hz, unitPresentation: UnitHelper.DefaultPresentation);
101-
string resolution = ChronometerResolution.ToString(UnitHelper.DefaultPresentation);
100+
string frequency = PerfolizerMeasurementFormatter.Instance.Format(
101+
ChronometerFrequency.ToMeasurement(FrequencyUnit.Hz),
102+
unitPresentation: UnitHelper.DefaultPresentation);
103+
string resolution = PerfolizerMeasurementFormatter.Instance.Format(
104+
ChronometerResolution.ToMeasurement(),
105+
format: "0.000",
106+
unitPresentation: UnitHelper.DefaultPresentation);
102107
string timer = HardwareTimerKind.ToString().ToUpper();
103108
yield return $"Frequency: {frequency}, Resolution: {resolution}, Timer: {timer}";
104109
}

src/BenchmarkDotNet/Extensions/StatisticsExtensions.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using Perfolizer.Horology;
99
using Perfolizer.Mathematics.Histograms;
1010
using Perfolizer.Mathematics.Multimodality;
11+
using Perfolizer.Metrology;
1112

1213
namespace BenchmarkDotNet.Extensions
1314
{
@@ -18,7 +19,10 @@ public static class StatisticsExtensions
1819
public static Func<double, string> CreateNanosecondFormatter(this Statistics s, CultureInfo cultureInfo, string format = "N3")
1920
{
2021
var timeUnit = TimeUnit.GetBestTimeUnit(s.Mean);
21-
return x => TimeInterval.FromNanoseconds(x).ToString(timeUnit, format, cultureInfo, UnitHelper.DefaultPresentation);
22+
return x => PerfolizerMeasurementFormatter.Instance.Format(
23+
TimeInterval.FromNanoseconds(x).ToMeasurement(timeUnit),
24+
format, cultureInfo, UnitHelper.DefaultPresentation
25+
);
2226
}
2327

2428
[PublicAPI]

src/BenchmarkDotNet/Helpers/UnitHelper.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using Perfolizer.Horology;
22
using Perfolizer.Metrology;
3+
using Pragmastat.Metrology;
34

45
namespace BenchmarkDotNet.Helpers;
56

src/BenchmarkDotNet/Mathematics/PercentileValues.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using JetBrains.Annotations;
77
using Perfolizer;
88
using Perfolizer.Mathematics.QuantileEstimators;
9+
using Pragmastat;
910

1011
namespace BenchmarkDotNet.Mathematics
1112
{

0 commit comments

Comments
 (0)