Last active
November 7, 2024 18:52
-
-
Save cbarraco/4b478834c8a474fb0472d05ba1f870ab to your computer and use it in GitHub Desktop.
Discovers all classes in the assembly that have [Benchmark] attributes and runs them with BenchmarkRunner (BenchmarkDotNet)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static Type[] GetAllTypesThatHaveBenchmarkMethods() | |
{ | |
return Assembly.GetExecutingAssembly().GetTypes().Where( | |
type => type.GetMethods().Any( | |
method => method.GetCustomAttributes(typeof(BenchmarkAttribute)).Any() | |
) | |
).ToArray(); | |
} | |
var benchmarkTypes = GetAllTypesThatHaveBenchmarkMethods(); | |
foreach (var type in benchmarkTypes) | |
{ | |
Console.WriteLine($"Benchmarking {type.FullName}"); | |
BenchmarkRunner.Run(type); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment