Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Micro benchmark fixes #12178

Merged
merged 5 commits into from
Feb 1, 2023
Merged
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
2 changes: 1 addition & 1 deletion src/Core/tests/Benchmarks.Droid/Benchmarks.Droid.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<Using Include="BenchmarkDotNet.Loggers" />
<Using Include="BenchmarkDotNet.Order" />
<Using Include="BenchmarkDotNet.Running" />
<PackageReference Include="BenchmarkDotNet" Version="0.13.2" />
<PackageReference Include="BenchmarkDotNet" Version="0.13.3" />
<PackageReference Include="Xamarin.Android.Glide" Version="4.13.2.2" />
</ItemGroup>
<ItemGroup>
Expand Down
2 changes: 0 additions & 2 deletions src/Core/tests/Benchmarks.Droid/ImageBenchmarks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ namespace Benchmarks.Droid;
// SimpleTarget is apparently obsolete?
#pragma warning disable CS0612

[MemoryDiagnoser]
[Orderer(SummaryOrderPolicy.FastestToSlowest)]
public class ImageBenchmark
{
AImageView? imageView;
Expand Down
44 changes: 7 additions & 37 deletions src/Core/tests/Benchmarks.Droid/MainInstrumentation.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using BenchmarkDotNet.Diagnosers;
using BenchmarkDotNet.Toolchains.InProcess.Emit;

namespace Benchmarks.Droid;
Expand Down Expand Up @@ -35,29 +36,14 @@ static bool Run()
bool success = false;
try
{
// NOTE: this is mostly working around bugs in BenchmarkDotNet configuration
var logger = new Logger();
var baseConfig = new DebugInProcessConfig();

var config = new ManualConfig();

foreach (var e in baseConfig.GetExporters())
config.AddExporter(e);
foreach (var d in baseConfig.GetDiagnosers())
config.AddDiagnoser(d);
foreach (var a in baseConfig.GetAnalysers())
config.AddAnalyser(a);
foreach (var v in baseConfig.GetValidators())
config.AddValidator(v);
foreach (var p in baseConfig.GetColumnProviders())
config.AddColumnProvider(p);
config.AddJob(JobMode<Job>.Default.WithToolchain(new InProcessEmitToolchain(TimeSpan.FromMinutes(10), logOutput: true)));
config.UnionRule = ConfigUnionRule.AlwaysUseGlobal; // Overriding the default
config.AddLogger(logger);
var config = ManualConfig.CreateMinimumViable()
.AddJob(Job.Default.WithToolchain(new InProcessEmitToolchain(TimeSpan.FromMinutes(10), logOutput: true)))
.AddDiagnoser(MemoryDiagnoser.Default)
.WithOrderer(new DefaultOrderer(SummaryOrderPolicy.FastestToSlowest, MethodOrderPolicy.Alphabetical));

// ImageBenchmark class is hardcoded here for now
BenchmarkRunner.Run<ImageBenchmark>(config.WithOptions(ConfigOptions.DisableLogFile));
BenchmarkRunner.Run<ViewHandlerBenchmark>(config.WithOptions(ConfigOptions.DisableLogFile));
BenchmarkRunner.Run<ImageBenchmark>(config);
BenchmarkRunner.Run<ViewHandlerBenchmark>(config);

success = true;
}
Expand All @@ -67,20 +53,4 @@ static bool Run()
}
return success;
}

// NOTE: the built-in ConsoleLogger throws PlatformNotSupportedException
class Logger : ILogger
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was there a fix in BDN for the logger? My memory is that some System.Console API threw a PlatformNotSupported exception on Android. I don't remember if I sent a PR for it.

If you ran this on Android and it worked, we're good. I think it threw immediately when benchmarks started.

{
public string Id => "AndroidLogger";

public int Priority => 0;

public void Flush() { }

public void Write(LogKind logKind, string text) => Console.Write(text);

public void WriteLine() => Console.WriteLine();

public void WriteLine(LogKind logKind, string text) => Console.WriteLine(text);
}
}
2 changes: 0 additions & 2 deletions src/Core/tests/Benchmarks.Droid/ViewHandlerBenchmark.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@

namespace Benchmarks.Droid;

[MemoryDiagnoser]
[Orderer(SummaryOrderPolicy.FastestToSlowest)]
public class ViewHandlerBenchmark
{
readonly MauiContext _context = new();
Expand Down