Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
@@ -0,0 +1,39 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System;
using System.Linq;
using System.Reflection;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Running;
using BenchmarkDotNet.Configs;
using BenchmarkDotNet.Jobs;
using BenchmarkDotNet.Toolchains.InProcess;

namespace BenchmarkDotNet.Attributes
{
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Assembly)]
public class AspNetCoreBenchmarkAttribute : Attribute, IConfigSource

Choose a reason for hiding this comment

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

Make these types internal

{
public static bool UseValidationConfig { get; set; }

public Type ConfigType { get;set; }

Choose a reason for hiding this comment

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

Get only (or remove the ctors)

public Type ValidationConfigType { get;set; }

public AspNetCoreBenchmarkAttribute() : this(typeof(CoreConfig))
{
}

public AspNetCoreBenchmarkAttribute(Type configType) : this(configType, typeof(CoreValidationConfig))
{
}

public AspNetCoreBenchmarkAttribute(Type configType, Type validationConfigType)
{
ConfigType = configType;
ValidationConfigType = validationConfigType;
}

public IConfig Config => (IConfig) Activator.CreateInstance(UseValidationConfig ? ValidationConfigType : ConfigType, Array.Empty<object>());
}
}
39 changes: 39 additions & 0 deletions shared/Microsoft.AspNetCore.BenchmarkRunner.Sources/CoreConfig.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using BenchmarkDotNet.Columns;
using BenchmarkDotNet.Configs;
using BenchmarkDotNet.Diagnosers;
using BenchmarkDotNet.Engines;
using BenchmarkDotNet.Exporters;
using BenchmarkDotNet.Jobs;
using BenchmarkDotNet.Loggers;
using BenchmarkDotNet.Toolchains.CsProj;
using BenchmarkDotNet.Toolchains.DotNetCli;
using BenchmarkDotNet.Validators;

namespace BenchmarkDotNet.Attributes
{
public class CoreConfig : ManualConfig

Choose a reason for hiding this comment

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

DefaultConfig?

{
public CoreConfig()
{
Add(ConsoleLogger.Default);
Add(MarkdownExporter.GitHub);

Add(MemoryDiagnoser.Default);
Add(StatisticColumn.OperationsPerSecond);

Add(JitOptimizationsValidator.FailOnError);

Add(Job.Core
.With(CsProjCoreToolchain.From(NetCoreAppSettings.NetCoreApp21))
.WithRemoveOutliers(false)
.With(new GcMode { Server = true })
.With(RunStrategy.Throughput)
.WithLaunchCount(3)
.WithWarmupCount(5)
.WithTargetCount(10));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System;
using System.Linq;
using System.Reflection;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Running;
using BenchmarkDotNet.Configs;
using BenchmarkDotNet.Jobs;
using BenchmarkDotNet.Loggers;
using BenchmarkDotNet.Toolchains.InProcess;

namespace BenchmarkDotNet.Attributes
{
public class CoreValidationConfig : ManualConfig
{
public CoreValidationConfig()
{
Add(ConsoleLogger.Default);

Add(Job.Dry.With(InProcessToolchain.Instance));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,14 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System;
using System.Linq;
using System.Reflection;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Running;
using BenchmarkDotNet.Configs;
using BenchmarkDotNet.Jobs;
using BenchmarkDotNet.Toolchains.InProcess;

namespace BenchmarkDotNet.Attributes
{
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Assembly)]
public class ParameterizedJobConfigAttribute : Attribute, IConfigSource
public class ParameterizedJobConfigAttribute: AspNetCoreBenchmarkAttribute
{
public static Job Job { get; set; }

public ParameterizedJobConfigAttribute(Type config)
public ParameterizedJobConfigAttribute(Type configType) : base(configType)
{
var args = Job != null ? new object[] { Job } : Array.Empty<object>();
Config = (IConfig) Activator.CreateInstance(config, args);
}

public IConfig Config { get; }
}
}
}
17 changes: 8 additions & 9 deletions shared/Microsoft.AspNetCore.BenchmarkRunner.Sources/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,17 @@

namespace Microsoft.AspNetCore.BenchmarkDotNet.Runner
{
class Program
partial class Program
{
private static TextWriter _standardOutput;
private static StringBuilder _standardOutputText;

static partial void BeforeMain(string[] args);

Choose a reason for hiding this comment

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

Nice


private static int Main(string[] args)
{
BeforeMain(args);

CheckValidate(ref args);
var summaries = BenchmarkSwitcher.FromAssembly(typeof(Program).GetTypeInfo().Assembly)
.Run(args, ManualConfig.CreateEmpty());
Expand Down Expand Up @@ -65,15 +69,10 @@ private static int Fail(object o, string message)
private static void CheckValidate(ref string[] args)
{
var argsList = args.ToList();
if (argsList.Remove("--validate"))
{
SuppressConsole();
ParameterizedJobConfigAttribute.Job = Job.Dry;
}
else if (argsList.Remove("--validate-fast"))
if (argsList.Remove("--validate") || argsList.Remove("--validate-fast"))
{
SuppressConsole();
ParameterizedJobConfigAttribute.Job = Job.Dry.With(InProcessToolchain.Instance);
AspNetCoreBenchmarkAttribute.UseValidationConfig = true;
}

args = argsList.ToArray();
Expand All @@ -86,4 +85,4 @@ private static void SuppressConsole()
Console.SetOut(new StringWriter(_standardOutputText));
}
}
}
}