Table of Contents

Sample: IntroTagColumn

In the following example, we introduce two new columns which contains a tag based on a benchmark method name.

Source code

using System.Threading;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Columns;
using BenchmarkDotNet.Configs;
using BenchmarkDotNet.Jobs;

namespace BenchmarkDotNet.Samples
{
    // You can add custom tags per each method using Columns
    [Config(typeof(Config))]
    public class IntroTagColumn
    {
        private class Config : ManualConfig
        {
            public Config()
            {
                AddJob(Job.Dry);
                AddColumn(new TagColumn("Kind", name => name.Substring(0, 3)));
                AddColumn(new TagColumn("Number", name => name.Substring(3)));
            }
        }

        [Benchmark]
        public void Foo1() => Thread.Sleep(10);

        [Benchmark]
        public void Foo12() => Thread.Sleep(10);

        [Benchmark]
        public void Bar3() => Thread.Sleep(10);

        [Benchmark]
        public void Bar34() => Thread.Sleep(10);
    }
}

Output

| Method | Mean       | Kind | Number |
| ------ | ---------- | ---- | ------ |
| Bar34  | 10.3636 ms | Bar  | 34     |
| Bar3   | 10.4662 ms | Bar  | 3      |
| Foo12  | 10.1377 ms | Foo  | 12     |
| Foo1   | 10.2814 ms | Foo  | 1      |