Skip to content

Instantly share code, notes, and snippets.

@EgorBo
Created March 6, 2021 19:57
Show Gist options
  • Save EgorBo/8766a778fa2522fad4e916c567a2b5d7 to your computer and use it in GitHub Desktop.
Save EgorBo/8766a778fa2522fad4e916c567a2b5d7 to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using BenchmarkDotNet.Attributes;
public class P
{
static void Main(string[] args)
{
BenchmarkDotNet.Running.BenchmarkSwitcher.FromAssembly(typeof(P).Assembly).Run(args);
}
public static IEnumerable<object> TestData()
{
//yield return new BaseClass();
//yield return new SubClass3();
yield return new SubClass6();
}
[Benchmark()]
[ArgumentsSource(nameof(TestData))]
public bool IsBaseClass(object o) => o is BaseClass;
[Benchmark()]
[ArgumentsSource(nameof(TestData))]
public bool IsSubClass1(object o) => o is SubClass1;
[Benchmark()]
[ArgumentsSource(nameof(TestData))]
public bool IsSubClass2(object o) => o is SubClass2;
[Benchmark()]
[ArgumentsSource(nameof(TestData))]
public bool IsSubClass3(object o) => o is SubClass3;
[Benchmark()]
[ArgumentsSource(nameof(TestData))]
public bool IsSubClass4(object o) => o is SubClass4;
[Benchmark()]
[ArgumentsSource(nameof(TestData))]
public bool IsSubClass5(object o) => o is SubClass5;
[Benchmark(Baseline = true)]
[ArgumentsSource(nameof(TestData))]
public bool IsSubClass6(object o) => o is SubClass6;
}
public class BaseClass : Object { }
public class SubClass1 : BaseClass { }
public class SubClass2 : SubClass1 { }
public class SubClass3 : SubClass2 { }
public class SubClass4 : SubClass3 { }
public class SubClass5 : SubClass4 { }
public class SubClass6 : SubClass5 { }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment