diff --git a/src/benchmarks/real-world/Akade.IndexedSet.Benchmarks/Program.cs b/src/benchmarks/real-world/Akade.IndexedSet.Benchmarks/Program.cs index d0a1244468f..9c8cb8f3b7a 100644 --- a/src/benchmarks/real-world/Akade.IndexedSet.Benchmarks/Program.cs +++ b/src/benchmarks/real-world/Akade.IndexedSet.Benchmarks/Program.cs @@ -3,6 +3,10 @@ using BenchmarkDotNet.Running; using System.Collections.Immutable; -BenchmarkSwitcher.FromAssembly(typeof(Program).Assembly).Run(args, RecommendedConfig.Create( +// Use RunAsync (not Run) so BDN does not install its single-threaded +// BenchmarkDotNetSynchronizationContext on the entrypoint thread. +var summaries = await BenchmarkSwitcher.FromAssembly(typeof(Program).Assembly).RunAsync(args, RecommendedConfig.Create( artifactsPath: new DirectoryInfo(Path.Combine(Path.GetDirectoryName(typeof(Program).Assembly.Location)!, "BenchmarkDotNet.Artifacts")), - mandatoryCategories: ImmutableHashSet.Create(Categories.AkadeIndexedSet))); \ No newline at end of file + mandatoryCategories: ImmutableHashSet.Create(Categories.AkadeIndexedSet))) + .ConfigureAwait(false); +return summaries.ToExitCode(); \ No newline at end of file diff --git a/src/benchmarks/real-world/ILLink/Program.cs b/src/benchmarks/real-world/ILLink/Program.cs index d57eb05a15a..3147069face 100644 --- a/src/benchmarks/real-world/ILLink/Program.cs +++ b/src/benchmarks/real-world/ILLink/Program.cs @@ -4,6 +4,7 @@ using System.Collections.Immutable; using System.IO; using System.Reflection; +using System.Threading.Tasks; using BenchmarkDotNet.Engines; using BenchmarkDotNet.Extensions; using BenchmarkDotNet.Jobs; @@ -13,7 +14,9 @@ namespace ILLinkBenchmarks; public class ILLinkBench { - public static int Main(string[] args) + // Use RunAsync (not Run) so BDN does not install its single-threaded + // BenchmarkDotNetSynchronizationContext on the entrypoint thread. + public static async Task Main(string[] args) { string thisAssembly = Assembly.GetExecutingAssembly().Location; string sampleProjectFile = Path.Combine(Path.GetDirectoryName(thisAssembly), "SampleProject", "HelloWorld.csproj"); @@ -29,13 +32,14 @@ public static int Main(string[] args) .WithStrategy(RunStrategy.Monitoring) .WithMaxRelativeError(0.01); - return BenchmarkSwitcher + var summaries = await BenchmarkSwitcher .FromAssembly(typeof(BasicBenchmark).Assembly) - .Run(args, RecommendedConfig.Create( + .RunAsync(args, RecommendedConfig.Create( artifactsPath: new DirectoryInfo(Path.Combine(Path.GetDirectoryName(typeof(BasicBenchmark).Assembly.Location), "BenchmarkDotNet.Artifacts")), mandatoryCategories: ImmutableHashSet.Create("ILLink"), job: job)) - .ToExitCode(); + .ConfigureAwait(false); + return summaries.ToExitCode(); } } \ No newline at end of file diff --git a/src/benchmarks/real-world/ImageSharp/Program.cs b/src/benchmarks/real-world/ImageSharp/Program.cs index f97854cce8c..85229ca9587 100644 --- a/src/benchmarks/real-world/ImageSharp/Program.cs +++ b/src/benchmarks/real-world/ImageSharp/Program.cs @@ -5,6 +5,7 @@ using BenchmarkDotNet.Running; using System.Collections.Immutable; using System.IO; +using System.Threading.Tasks; namespace SixLabors.ImageSharp.Benchmarks { @@ -16,10 +17,17 @@ public class Program /// /// The arguments to pass to the program. /// - public static void Main(string[] args) => BenchmarkSwitcher - .FromAssembly(typeof(Program).Assembly) - .Run(args, RecommendedConfig.Create( - artifactsPath: new DirectoryInfo(Path.Combine(Path.GetDirectoryName(typeof(Program).Assembly.Location), "BenchmarkDotNet.Artifacts")), - mandatoryCategories: ImmutableHashSet.Create(Categories.ImageSharp))); + // Use RunAsync (not Run) so BDN does not install its single-threaded + // BenchmarkDotNetSynchronizationContext on the entrypoint thread. + public static async Task Main(string[] args) + { + var summaries = await BenchmarkSwitcher + .FromAssembly(typeof(Program).Assembly) + .RunAsync(args, RecommendedConfig.Create( + artifactsPath: new DirectoryInfo(Path.Combine(Path.GetDirectoryName(typeof(Program).Assembly.Location), "BenchmarkDotNet.Artifacts")), + mandatoryCategories: ImmutableHashSet.Create(Categories.ImageSharp))) + .ConfigureAwait(false); + return summaries.ToExitCode(); + } } } diff --git a/src/benchmarks/real-world/Microsoft.ML.Benchmarks/Program.cs b/src/benchmarks/real-world/Microsoft.ML.Benchmarks/Program.cs index 619c66589ae..fdf8d6918db 100644 --- a/src/benchmarks/real-world/Microsoft.ML.Benchmarks/Program.cs +++ b/src/benchmarks/real-world/Microsoft.ML.Benchmarks/Program.cs @@ -6,6 +6,7 @@ using System.Globalization; using System.IO; using System.Threading; +using System.Threading.Tasks; using BenchmarkDotNet.Running; using BenchmarkDotNet.Extensions; @@ -17,13 +18,18 @@ class Program /// execute dotnet run -c Release and choose the benchmarks you want to run /// /// - static int Main(string[] args) - => BenchmarkSwitcher + // Use RunAsync (not Run) so BDN does not install its single-threaded + // BenchmarkDotNetSynchronizationContext on the entrypoint thread. + static async Task Main(string[] args) + { + var summaries = await BenchmarkSwitcher .FromAssembly(typeof(Program).Assembly) - .Run(args, RecommendedConfig.Create( - artifactsPath: new DirectoryInfo(Path.Combine(Path.GetDirectoryName(typeof(Program).Assembly.Location), "BenchmarkDotNet.Artifacts")), + .RunAsync(args, RecommendedConfig.Create( + artifactsPath: new DirectoryInfo(Path.Combine(Path.GetDirectoryName(typeof(Program).Assembly.Location), "BenchmarkDotNet.Artifacts")), mandatoryCategories: ImmutableHashSet.Create(Categories.MachineLearning))) - .ToExitCode(); + .ConfigureAwait(false); + return summaries.ToExitCode(); + } internal static string GetInvariantCultureDataPath(string name) { diff --git a/src/benchmarks/real-world/Microsoft.ML.Benchmarks/StochasticDualCoordinateAscentClassifierBench.cs b/src/benchmarks/real-world/Microsoft.ML.Benchmarks/StochasticDualCoordinateAscentClassifierBench.cs index 14ae66abee2..0708860eedc 100644 --- a/src/benchmarks/real-world/Microsoft.ML.Benchmarks/StochasticDualCoordinateAscentClassifierBench.cs +++ b/src/benchmarks/real-world/Microsoft.ML.Benchmarks/StochasticDualCoordinateAscentClassifierBench.cs @@ -4,6 +4,7 @@ using System.Collections.Generic; using System.Globalization; +using System.Threading; using BenchmarkDotNet.Attributes; using BenchmarkDotNet.Engines; using Microsoft.ML.Data; @@ -75,39 +76,51 @@ private TransformerChain Main(string[] args) { var argsList = new List(args); int? partitionCount; @@ -38,9 +41,9 @@ public static int Main(string[] args) return 1; } - return BenchmarkSwitcher + var summaries = await BenchmarkSwitcher .FromAssembly(typeof(Program).Assembly) - .Run( + .RunAsync( argsList.ToArray(), RecommendedConfig.Create( artifactsPath: new DirectoryInfo(Path.Combine(Path.GetDirectoryName(typeof(Program).Assembly.Location), "BenchmarkDotNet.Artifacts")), @@ -50,7 +53,8 @@ public static int Main(string[] args) exclusionFilterValue: exclusionFilterValue, categoryExclusionFilterValue: categoryExclusionFilterValue, getDiffableDisasm: getDiffableDisasm)) - .ToExitCode(); + .ConfigureAwait(false); + return summaries.ToExitCode(); } } } diff --git a/src/benchmarks/real-world/Roslyn/Program.cs b/src/benchmarks/real-world/Roslyn/Program.cs index dcd2096b6d7..f2116956b44 100644 --- a/src/benchmarks/real-world/Roslyn/Program.cs +++ b/src/benchmarks/real-world/Roslyn/Program.cs @@ -20,11 +20,14 @@ // to communicate information is pass by environment variable Environment.SetEnvironmentVariable(Helpers.TestProjectEnvVarName, sourceDir); -return BenchmarkSwitcher +// Use RunAsync (not Run) so BDN does not install its single-threaded +// BenchmarkDotNetSynchronizationContext on the entrypoint thread. +var summaries = await BenchmarkSwitcher .FromAssembly(typeof(Helpers).Assembly) - .Run(args, RecommendedConfig.Create( + .RunAsync(args, RecommendedConfig.Create( artifactsPath: new DirectoryInfo(Path.Combine(Path.GetDirectoryName(typeof(Helpers).Assembly.Location), "BenchmarkDotNet.Artifacts")), mandatoryCategories: ImmutableHashSet.Create("Roslyn"), job: Job.Default.WithMaxRelativeError(0.01))) - .ToExitCode(); + .ConfigureAwait(false); +return summaries.ToExitCode(); diff --git a/src/benchmarks/real-world/bepuphysics2/Program.cs b/src/benchmarks/real-world/bepuphysics2/Program.cs index f09fff1f790..ff67c617193 100644 --- a/src/benchmarks/real-world/bepuphysics2/Program.cs +++ b/src/benchmarks/real-world/bepuphysics2/Program.cs @@ -3,14 +3,20 @@ using BenchmarkDotNet.Running; using DemoBenchmarks; using System.Collections.Immutable; +using System.Threading.Tasks; public class BepuPhysics2Benchmarks { - public static void Main(string[] args) => - BenchmarkSwitcher + // Use RunAsync (not Run) so BDN does not install its single-threaded + // BenchmarkDotNetSynchronizationContext on the entrypoint thread. + public static async Task Main(string[] args) + { + var summaries = await BenchmarkSwitcher .FromAssembly(typeof(BepuPhysics2Benchmarks).Assembly) - .Run(args, RecommendedConfig.Create( + .RunAsync(args, RecommendedConfig.Create( artifactsPath: new DirectoryInfo(Path.Combine(Path.GetDirectoryName(typeof(BepuPhysics2Benchmarks).Assembly.Location), "BenchmarkDotNet.Artifacts")), mandatoryCategories: ImmutableHashSet.Create(Categories.BepuPhysics))) - .ToExitCode(); + .ConfigureAwait(false); + return summaries.ToExitCode(); + } }