Skip to content

Commit dfb94a1

Browse files
committed
chore: reflect review comments and cleanup codes
1 parent 04e87b7 commit dfb94a1

File tree

3 files changed

+28
-37
lines changed

3 files changed

+28
-37
lines changed
Lines changed: 7 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
1-
using BenchmarkDotNet.Attributes;
2-
using BenchmarkDotNet.Configs;
3-
using BenchmarkDotNet.Diagnosers;
1+
using BenchmarkDotNet.Configs;
42
using BenchmarkDotNet.Engines;
53
using BenchmarkDotNet.Exporters;
4+
using BenchmarkDotNet.Extensions;
65
using BenchmarkDotNet.Loggers;
7-
using BenchmarkDotNet.Reports;
86
using BenchmarkDotNet.Running;
97
using System;
10-
using System.Collections.Generic;
118
using System.Linq;
129

1310
namespace BenchmarkDotNet.Samples;
@@ -49,37 +46,13 @@ public static int Main(string[] args)
4946
args = args.Where(x => x != "--inProcess").ToArray();
5047

5148
DebugConfig config = isInProcess
52-
? new DebugInProcessConfig()
53-
: new DebugBuildConfig();
49+
? new DebugInProcessConfig()
50+
: new DebugBuildConfig();
5451

5552
return config.AddAnalyser(DefaultConfig.Instance.GetAnalysers().ToArray())
56-
.AddDiagnoser(
57-
MemoryDiagnoser.Default,
58-
#if NETCOREAPP3_0_OR_GREATER
59-
new ThreadingDiagnoser(new ThreadingDiagnoserConfig(displayCompletedWorkItemCountWhenZero: false, displayLockContentionWhenZero: false)),
53+
.AddExporter(MarkdownExporter.Default)
54+
.AddValidator(DefaultConfig.Instance.GetValidators().ToArray())
55+
.WithArtifactsPath(DefaultConfig.Instance.ArtifactsPath);
6056
#endif
61-
new ExceptionDiagnoser(new ExceptionDiagnoserConfig(displayExceptionsIfZeroValue: false))
62-
)
63-
.AddExporter(MarkdownExporter.Default)
64-
.AddValidator(DefaultConfig.Instance.GetValidators().ToArray())
65-
.WithArtifactsPath(DefaultConfig.Instance.ArtifactsPath);
66-
#endif
67-
}
68-
}
69-
70-
file static class ExtensionMethods
71-
{
72-
public static bool HasError(this Summary[] summaries)
73-
{
74-
if (summaries.Length == 0)
75-
{
76-
var hashSet = new HashSet<string>(["--help", "--list", "--info", "--version"]);
77-
return !Environment.GetCommandLineArgs().Any(hashSet.Contains);
78-
}
79-
80-
if (summaries.Any(x => x.HasCriticalValidationErrors))
81-
return true;
82-
83-
return summaries.Any(x => x.Reports.Any(r => !r.Success));
8457
}
8558
}

samples/BenchmarkDotNet.Samples/Properties/launchSettings.json

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,18 @@
33
"Default": {
44
"commandName": "Project",
55
"commandLineArgs": "",
6-
"workingDirectory": ".",
76
"environmentVariables": {
87
}
98
},
109
"Run IntroBasic Benchmarks": {
1110
"commandName": "Project",
1211
"commandLineArgs": "--filter *IntroBasic*",
13-
// "commandLineArgs": "--filter *IntroBasic* --inProcess --strategy Monitoring", // Use this setting for in-process debug
14-
"workingDirectory": ".",
12+
"environmentVariables": {
13+
}
14+
},
15+
"Run IntroBasic Benchmarks with --inProcess": {
16+
"commandName": "Project",
17+
"commandLineArgs": "--filter *IntroBasic* --inProcess",
1518
"environmentVariables": {
1619
}
1720
},

src/BenchmarkDotNet/Extensions/ReportExtensions.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,20 @@ public static Statistics GetStatistics(this IReadOnlyCollection<Measurement> run
3434

3535
public static Statistics GetStatistics(this IEnumerable<Measurement> runs) =>
3636
GetStatistics(runs.ToList());
37+
38+
public static bool HasError(this IEnumerable<Summary> summaries)
39+
{
40+
if (summaries.Count() == 0)
41+
{
42+
// When following argument specified. BenchmarkDotNet show information only.
43+
var knownArguments = new HashSet<string>(["--help", "--list", "--info", "--version"]);
44+
return !Environment.GetCommandLineArgs().Any(knownArguments.Contains);
45+
}
46+
47+
if (summaries.Any(x => x.HasCriticalValidationErrors))
48+
return true;
49+
50+
return summaries.Any(x => x.Reports.Any(r => !r.Success));
51+
}
3752
}
3853
}

0 commit comments

Comments
 (0)