diff --git a/samples/BenchmarkDotNet.Samples/IntroRenameTest.cs b/samples/BenchmarkDotNet.Samples/IntroRenameTest.cs new file mode 100644 index 0000000000..67c9946ac4 --- /dev/null +++ b/samples/BenchmarkDotNet.Samples/IntroRenameTest.cs @@ -0,0 +1,22 @@ +using BenchmarkDotNet.Attributes; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading; +using System.Threading.Tasks; + +namespace BenchmarkDotNet.Samples +{ + [BenchmarkName("Used to be 'IntroRenameTest', now is 'My Renamed Test'")] + public class IntroRenameTest + { + // And define a method with the Benchmark attribute + [Benchmark] + public void Sleep() => Thread.Sleep(10); + + // You can write a description for your method. + [Benchmark(Description = "Thread.Sleep(10)")] + public void SleepWithDescription() => Thread.Sleep(10); + } +} diff --git a/src/BenchmarkDotNet.Annotations/Attributes/BenchmarkNameAttribute.cs b/src/BenchmarkDotNet.Annotations/Attributes/BenchmarkNameAttribute.cs new file mode 100644 index 0000000000..0c31ad064c --- /dev/null +++ b/src/BenchmarkDotNet.Annotations/Attributes/BenchmarkNameAttribute.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace BenchmarkDotNet.Attributes +{ + [AttributeUsage(AttributeTargets.Class)] + public class BenchmarkNameAttribute : Attribute + { + public BenchmarkNameAttribute(){ } + public BenchmarkNameAttribute(string name) + => Name = name; + + public string Name { get; set; } + } +} diff --git a/src/BenchmarkDotNet/Extensions/ReflectionExtensions.cs b/src/BenchmarkDotNet/Extensions/ReflectionExtensions.cs index cf711a708b..eaf2dc295f 100644 --- a/src/BenchmarkDotNet/Extensions/ReflectionExtensions.cs +++ b/src/BenchmarkDotNet/Extensions/ReflectionExtensions.cs @@ -86,6 +86,10 @@ internal static string GetCorrectCSharpTypeName(this Type type, bool includeName /// private static string GetDisplayName(this TypeInfo typeInfo) { + var customAttr = typeInfo.GetCustomAttribute(); + if (customAttr != null) + return customAttr.Name; + if (!typeInfo.IsGenericType) return typeInfo.Name; diff --git a/tests/BenchmarkDotNet.Tests/Exporters/ApprovedFiles/MarkdownExporterApprovalTests.GroupExporterTest.JobBaseline_RenameJob_MethodsJobs.approved.txt b/tests/BenchmarkDotNet.Tests/Exporters/ApprovedFiles/MarkdownExporterApprovalTests.GroupExporterTest.JobBaseline_RenameJob_MethodsJobs.approved.txt new file mode 100644 index 0000000000..e8edaa833f --- /dev/null +++ b/tests/BenchmarkDotNet.Tests/Exporters/ApprovedFiles/MarkdownExporterApprovalTests.GroupExporterTest.JobBaseline_RenameJob_MethodsJobs.approved.txt @@ -0,0 +1,20 @@ +=== JobBaseline_RenameJob_MethodsJobs === + +BenchmarkDotNet=v0.10.x-mock, OS=Microsoft Windows NT 10.0.x.mock, VM=Hyper-V +MockIntel Core i7-6700HQ CPU 2.60GHz (Max: 3.10GHz), 1 CPU, 8 logical and 4 physical cores +Frequency=2531248 Hz, Resolution=395.0620 ns, Timer=TSC + [Host] : Clr 4.0.x.mock, 64mock RyuJIT-v4.6.x.mock CONFIGURATION + Job1 : extra output line + Job2 : extra output line + + + Method | Job | Mean | Error | StdDev | Rank | LogicalGroup | Baseline | +------- |----- |---------:|--------:|--------:|-----:|------------- |--------- | + Base | Job1 | 102.0 ns | 6.09 ns | 1.58 ns | 1 | * | No | + Foo | Job1 | 202.0 ns | 6.09 ns | 1.58 ns | 2 | * | No | + Bar | Job1 | 302.0 ns | 6.09 ns | 1.58 ns | 3 | * | No | + Base | Job2 | 402.0 ns | 6.09 ns | 1.58 ns | 4 | * | No | + Foo | Job2 | 502.0 ns | 6.09 ns | 1.58 ns | 5 | * | No | + Bar | Job2 | 602.0 ns | 6.09 ns | 1.58 ns | 6 | * | No | + +Errors: 0 diff --git a/tests/BenchmarkDotNet.Tests/Exporters/MarkdownExporterApprovalTests.cs b/tests/BenchmarkDotNet.Tests/Exporters/MarkdownExporterApprovalTests.cs index 2d673d7742..2b8167c0da 100644 --- a/tests/BenchmarkDotNet.Tests/Exporters/MarkdownExporterApprovalTests.cs +++ b/tests/BenchmarkDotNet.Tests/Exporters/MarkdownExporterApprovalTests.cs @@ -199,6 +199,16 @@ [Benchmark] public void Bar() { } /* JobBaseline */ + [RankColumn, LogicalGroupColumn, BaselineColumn] + [SimpleJob(id: "Job1"), SimpleJob(id: "Job2")] + [BenchmarkDotNet.Attributes.BenchmarkName(Name = "MyRenamedTestCase")] + public class JobBaseline_RenameJob_MethodsJobs + { + [Benchmark] public void Base() { } + [Benchmark] public void Foo() { } + [Benchmark] public void Bar() { } + } + [RankColumn, LogicalGroupColumn, BaselineColumn] [SimpleJob(id: "Job1", baseline: true), SimpleJob(id: "Job2")] public class JobBaseline_MethodsJobs