Skip to content

Commit

Permalink
warn the users (once!) that if they run less than 15 iterations, the …
Browse files Browse the repository at this point in the history
…MultimodalDistributionAnalyzer is not going to work, dotnet#763
  • Loading branch information
adamsitnik authored and alinasmirnova committed Sep 22, 2018
1 parent a409803 commit 93e0302
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 11 deletions.
34 changes: 32 additions & 2 deletions src/BenchmarkDotNet/Analysers/Conclusion.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
using BenchmarkDotNet.Reports;
using System;
using BenchmarkDotNet.Reports;
using JetBrains.Annotations;

namespace BenchmarkDotNet.Analysers
{
// TODO: Find a better name
public sealed class Conclusion
public sealed class Conclusion : IEquatable<Conclusion>
{
[NotNull]
public string AnalyserId { get; }
Expand Down Expand Up @@ -33,5 +34,34 @@ public static Conclusion CreateWarning(string analyserId, string message, [CanBe

public static Conclusion CreateError(string analyserId, string message, [CanBeNull] BenchmarkReport report = null)
=> new Conclusion(analyserId, ConclusionKind.Error, message, report);

public bool Equals(Conclusion other)
{
if (ReferenceEquals(null, other))
return false;
if (ReferenceEquals(this, other))
return true;
return string.Equals(AnalyserId, other.AnalyserId) && Kind == other.Kind && string.Equals(Message, other.Message);
}

public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj))
return false;
if (ReferenceEquals(this, obj))
return true;
return obj is Conclusion && Equals((Conclusion) obj);
}

public override int GetHashCode()
{
unchecked
{
int hashCode = AnalyserId.GetHashCode();
hashCode = (hashCode * 397) ^ (int) Kind;
hashCode = (hashCode * 397) ^ Message.GetHashCode();
return hashCode;
}
}
}
}
16 changes: 11 additions & 5 deletions src/BenchmarkDotNet/Analysers/MultimodalDistributionAnalyzer.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using BenchmarkDotNet.Engines;
using BenchmarkDotNet.Mathematics;
using BenchmarkDotNet.Reports;
using JetBrains.Annotations;
Expand All @@ -7,20 +8,21 @@ namespace BenchmarkDotNet.Analysers
{
public class MultimodalDistributionAnalyzer : AnalyserBase
{
public override string Id => "MultimodalDistribution";
public static readonly IAnalyser Default = new MultimodalDistributionAnalyzer();

private MultimodalDistributionAnalyzer() { }

[NotNull]
private Conclusion Create([NotNull] string kind, double mValue, [CanBeNull] BenchmarkReport report)
=> CreateWarning($"It seems that the distribution {kind} (mValue = {mValue})", report);
public override string Id => "MultimodalDistribution";

public override IEnumerable<Conclusion> AnalyseReport(BenchmarkReport report, Summary summary)
{
var statistics = report.ResultStatistics;
if (statistics == null || statistics.N < 15)
if (statistics == null)
yield break;
if (statistics.N < EngineResolver.DefaultMinTargetIterationCount)
yield return CreateHint($"The number of iterations was set to less than {EngineResolver.DefaultMinTargetIterationCount}, " +
$"{nameof(MultimodalDistributionAnalyzer)} needs at least {EngineResolver.DefaultMinTargetIterationCount} iterations to work.");

double mValue = MathHelper.CalculateMValue(statistics);
if (mValue > 4.2)
yield return Create("is multimodal", mValue, report);
Expand All @@ -29,5 +31,9 @@ public override IEnumerable<Conclusion> AnalyseReport(BenchmarkReport report, Su
else if (mValue > 2.8)
yield return Create("can have several modes", mValue, report);
}

[NotNull]
private Conclusion Create([NotNull] string kind, double mValue, [CanBeNull] BenchmarkReport report)
=> CreateWarning($"It seems that the distribution {kind} (mValue = {mValue})", report);
}
}
9 changes: 6 additions & 3 deletions src/BenchmarkDotNet/Jobs/RunMode.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using BenchmarkDotNet.Characteristics;
using BenchmarkDotNet.Analysers;
using BenchmarkDotNet.Characteristics;
using BenchmarkDotNet.Engines;
using BenchmarkDotNet.Horology;

Expand Down Expand Up @@ -136,7 +137,8 @@ public int UnrollFactor

/// <summary>
/// Minimum count of target iterations that should be performed
/// The default is 15
/// The default value is 15
/// <remarks>If you set this value to below 15, then <see cref="MultimodalDistributionAnalyzer"/> is not going to work</remarks>
/// </summary>
public int MinTargetIterationCount
{
Expand All @@ -146,7 +148,8 @@ public int MinTargetIterationCount

/// <summary>
/// Maximum count of target iterations that should be performed
/// The default is 100
/// The default value is 100
/// <remarks>If you set this value to below 15, then <see cref="MultimodalDistributionAnalyzer"/> is not going to work</remarks>
/// </summary>
public int MaxTargetIterationCount
{
Expand Down
2 changes: 1 addition & 1 deletion src/BenchmarkDotNet/Running/BenchmarkRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ private static Summary Run(
MarkdownExporter.Console.ExportToLog(summary, logger);

// TODO: make exporter
ConclusionHelper.Print(logger, config.GetCompositeAnalyser().Analyse(summary).ToList());
ConclusionHelper.Print(logger, config.GetCompositeAnalyser().Analyse(summary).Distinct().ToList());

// TODO: move to conclusions
var columnWithLegends = summary.Table.Columns.Select(c => c.OriginalColumn).Where(c => !string.IsNullOrEmpty(c.Legend)).ToList();
Expand Down

0 comments on commit 93e0302

Please sign in to comment.