-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Expand file tree
/
Copy pathIntroCategoryDiscoverer.cs
More file actions
47 lines (41 loc) · 1.29 KB
/
IntroCategoryDiscoverer.cs
File metadata and controls
47 lines (41 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
using System;
using System.Collections.Generic;
using System.Reflection;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Configs;
using BenchmarkDotNet.Running;
namespace BenchmarkDotNet.Samples
{
[DryJob]
[UseLocalJobOnly]
[CategoriesColumn]
[CustomCategoryDiscoverer]
public class IntroCategoryDiscoverer
{
private class CustomCategoryDiscoverer : DefaultCategoryDiscoverer
{
public override string[] GetCategories(MethodInfo method)
{
var categories = new List<string>();
categories.AddRange(base.GetCategories(method));
categories.Add("All");
categories.Add(method.Name.Substring(0, 1));
return categories.ToArray();
}
}
[AttributeUsage(AttributeTargets.Class)]
private class CustomCategoryDiscovererAttribute : Attribute, IConfigSource
{
public CustomCategoryDiscovererAttribute()
{
Config = ManualConfig.CreateEmpty()
.WithCategoryDiscoverer(new CustomCategoryDiscoverer());
}
public IConfig Config { get; }
}
[Benchmark]
public void Foo() { }
[Benchmark]
public void Bar() { }
}
}