Skip to content
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
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)]
internal class AspNetCoreBenchmarkAttribute : Attribute, IConfigSource
{
public static bool UseValidationConfig { get; set; }

public Type ConfigType { get; }
public Type ValidationConfigType { get; }

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

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

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

public IConfig Config => (IConfig) Activator.CreateInstance(UseValidationConfig ? ValidationConfigType : ConfigType, Array.Empty<object>());
}
}
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
{
internal class DefaultCoreConfig : ManualConfig
{
public DefaultCoreConfig()
{
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
{
internal class DefaultCoreValidationConfig : ManualConfig
{
public DefaultCoreValidationConfig()
{
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
internal 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));
}
}
}
}