diff --git a/shared/Microsoft.AspNetCore.BenchmarkRunner.Sources/AspNetCoreBenchmarkAttribute.cs b/shared/Microsoft.AspNetCore.BenchmarkRunner.Sources/AspNetCoreBenchmarkAttribute.cs new file mode 100644 index 00000000000..a4044d1b5e8 --- /dev/null +++ b/shared/Microsoft.AspNetCore.BenchmarkRunner.Sources/AspNetCoreBenchmarkAttribute.cs @@ -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()); + } +} diff --git a/shared/Microsoft.AspNetCore.BenchmarkRunner.Sources/DefaultCoreConfig.cs b/shared/Microsoft.AspNetCore.BenchmarkRunner.Sources/DefaultCoreConfig.cs new file mode 100644 index 00000000000..1f844d51a0a --- /dev/null +++ b/shared/Microsoft.AspNetCore.BenchmarkRunner.Sources/DefaultCoreConfig.cs @@ -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)); + } + } +} diff --git a/shared/Microsoft.AspNetCore.BenchmarkRunner.Sources/DefaultCoreValidationConfig.cs b/shared/Microsoft.AspNetCore.BenchmarkRunner.Sources/DefaultCoreValidationConfig.cs new file mode 100644 index 00000000000..95fc725564d --- /dev/null +++ b/shared/Microsoft.AspNetCore.BenchmarkRunner.Sources/DefaultCoreValidationConfig.cs @@ -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)); + } + } +} diff --git a/shared/Microsoft.AspNetCore.BenchmarkRunner.Sources/ParameterizedJobConfigAttribute.cs b/shared/Microsoft.AspNetCore.BenchmarkRunner.Sources/ParameterizedJobConfigAttribute.cs index c7df649218d..9e0f947dc75 100644 --- a/shared/Microsoft.AspNetCore.BenchmarkRunner.Sources/ParameterizedJobConfigAttribute.cs +++ b/shared/Microsoft.AspNetCore.BenchmarkRunner.Sources/ParameterizedJobConfigAttribute.cs @@ -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(); - Config = (IConfig) Activator.CreateInstance(config, args); } - - public IConfig Config { get; } } -} \ No newline at end of file +} diff --git a/shared/Microsoft.AspNetCore.BenchmarkRunner.Sources/Program.cs b/shared/Microsoft.AspNetCore.BenchmarkRunner.Sources/Program.cs index e87472d5d94..3297d5dae98 100644 --- a/shared/Microsoft.AspNetCore.BenchmarkRunner.Sources/Program.cs +++ b/shared/Microsoft.AspNetCore.BenchmarkRunner.Sources/Program.cs @@ -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); + private static int Main(string[] args) { + BeforeMain(args); + CheckValidate(ref args); var summaries = BenchmarkSwitcher.FromAssembly(typeof(Program).GetTypeInfo().Assembly) .Run(args, ManualConfig.CreateEmpty()); @@ -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(); @@ -86,4 +85,4 @@ private static void SuppressConsole() Console.SetOut(new StringWriter(_standardOutputText)); } } -} \ No newline at end of file +}