Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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)));
mandatoryCategories: ImmutableHashSet.Create(Categories.AkadeIndexedSet)))
.ConfigureAwait(false);
return summaries.ToExitCode();
12 changes: 8 additions & 4 deletions src/benchmarks/real-world/ILLink/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<int> Main(string[] args)
{
string thisAssembly = Assembly.GetExecutingAssembly().Location;
string sampleProjectFile = Path.Combine(Path.GetDirectoryName(thisAssembly), "SampleProject", "HelloWorld.csproj");
Expand All @@ -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();
}
}
18 changes: 13 additions & 5 deletions src/benchmarks/real-world/ImageSharp/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using BenchmarkDotNet.Running;
using System.Collections.Immutable;
using System.IO;
using System.Threading.Tasks;

namespace SixLabors.ImageSharp.Benchmarks
{
Expand All @@ -16,10 +17,17 @@ public class Program
/// <param name="args">
/// The arguments to pass to the program.
/// </param>
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<int> 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();
}
}
}
16 changes: 11 additions & 5 deletions src/benchmarks/real-world/Microsoft.ML.Benchmarks/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Globalization;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
using BenchmarkDotNet.Running;
using BenchmarkDotNet.Extensions;

Expand All @@ -17,13 +18,18 @@ class Program
/// execute dotnet run -c Release and choose the benchmarks you want to run
/// </summary>
/// <param name="args"></param>
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<int> 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)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

using System.Collections.Generic;
using System.Globalization;
using System.Threading;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Engines;
using Microsoft.ML.Data;
Expand Down Expand Up @@ -75,39 +76,51 @@ private TransformerChain<MulticlassPredictionTransformer<MaximumEntropyModelPara
[Benchmark]
public void TrainSentiment()
{
// Pipeline
var arguments = new TextLoader.Options()
// BDN 0.16 installs BenchmarkDotNetSynchronizationContext in the child process.
// ML.NET's ApplyWordEmbedding downloads a pretrained model using sync-over-async
// I/O that deadlocks on the single-threaded SyncCtx. Clear it for this benchmark.
var savedCtx = SynchronizationContext.Current;
SynchronizationContext.SetSynchronizationContext(null);
try
{
Columns = new TextLoader.Column[]
// Pipeline
var arguments = new TextLoader.Options()
{
new TextLoader.Column("Label", DataKind.Single, new[] { new TextLoader.Range() { Min = 0, Max = 0 } }),
new TextLoader.Column("SentimentText", DataKind.String, new[] { new TextLoader.Range() { Min = 1, Max = 1 } })
},
HasHeader = true,
AllowQuoting = false,
AllowSparse = false
};

var loader = mlContext.Data.LoadFromTextFile(_sentimentDataPath, arguments);
var text = mlContext.Transforms.Text.FeaturizeText("WordEmbeddings", new TextFeaturizingEstimator.Options
Columns = new TextLoader.Column[]
{
new TextLoader.Column("Label", DataKind.Single, new[] { new TextLoader.Range() { Min = 0, Max = 0 } }),
new TextLoader.Column("SentimentText", DataKind.String, new[] { new TextLoader.Range() { Min = 1, Max = 1 } })
},
HasHeader = true,
AllowQuoting = false,
AllowSparse = false
};

var loader = mlContext.Data.LoadFromTextFile(_sentimentDataPath, arguments);
var text = mlContext.Transforms.Text.FeaturizeText("WordEmbeddings", new TextFeaturizingEstimator.Options
{
OutputTokensColumnName = "WordEmbeddings_TransformedText",
KeepPunctuations = false,
StopWordsRemoverOptions = new StopWordsRemovingEstimator.Options(),
Norm = TextFeaturizingEstimator.NormFunction.None,
CharFeatureExtractor = null,
WordFeatureExtractor = null,
}, "SentimentText").Fit(loader).Transform(loader);

var trans = mlContext.Transforms.Text.ApplyWordEmbedding("Features", "WordEmbeddings_TransformedText",
WordEmbeddingEstimator.PretrainedModelKind.SentimentSpecificWordEmbedding)
.Append(mlContext.Transforms.Conversion.MapValueToKey("Label"))
.Fit(text).Transform(text);

// Train
var trainer = mlContext.MulticlassClassification.Trainers.SdcaMaximumEntropy();
var predicted = trainer.Fit(trans);
_consumer.Consume(predicted);
}
finally
{
OutputTokensColumnName = "WordEmbeddings_TransformedText",
KeepPunctuations = false,
StopWordsRemoverOptions = new StopWordsRemovingEstimator.Options(),
Norm = TextFeaturizingEstimator.NormFunction.None,
CharFeatureExtractor = null,
WordFeatureExtractor = null,
}, "SentimentText").Fit(loader).Transform(loader);

var trans = mlContext.Transforms.Text.ApplyWordEmbedding("Features", "WordEmbeddings_TransformedText",
WordEmbeddingEstimator.PretrainedModelKind.SentimentSpecificWordEmbedding)
.Append(mlContext.Transforms.Conversion.MapValueToKey("Label"))
.Fit(text).Transform(text);

// Train
var trainer = mlContext.MulticlassClassification.Trainers.SdcaMaximumEntropy();
var predicted = trainer.Fit(trans);
_consumer.Consume(predicted);
SynchronizationContext.SetSynchronizationContext(savedCtx);
}
}

[GlobalSetup(Targets = new string[] { nameof(PredictIris), nameof(PredictIrisBatchOf1), nameof(PredictIrisBatchOf2), nameof(PredictIrisBatchOf5) })]
Expand Down
12 changes: 8 additions & 4 deletions src/benchmarks/real-world/PowerShell.Benchmarks/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,17 @@
using System.Collections.Generic;
using System.Collections.Immutable;
using System.IO;
using System.Threading.Tasks;
using BenchmarkDotNet.Running;
using BenchmarkDotNet.Extensions;

namespace MicroBenchmarks
{
public sealed class Program
{
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<int> Main(string[] args)
{
var argsList = new List<string>(args);
int? partitionCount;
Expand All @@ -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")),
Expand All @@ -50,7 +53,8 @@ public static int Main(string[] args)
exclusionFilterValue: exclusionFilterValue,
categoryExclusionFilterValue: categoryExclusionFilterValue,
getDiffableDisasm: getDiffableDisasm))
.ToExitCode();
.ConfigureAwait(false);
return summaries.ToExitCode();
}
}
}
9 changes: 6 additions & 3 deletions src/benchmarks/real-world/Roslyn/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
14 changes: 10 additions & 4 deletions src/benchmarks/real-world/bepuphysics2/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<int> 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();
}
}