DTLib.Demystifier/test/Ben.Demystifier.Benchmarks/Program.cs
Nick Craver 38d7faeda9 Add initial benchmark setup
This adds all the bootstrapping to quickly add benchmarks for pieces afterwards. Instructions for running added to the README.
2018-02-01 21:24:08 -05:00

49 lines
1.5 KiB
C#

using BenchmarkDotNet.Configs;
using BenchmarkDotNet.Diagnosers;
using BenchmarkDotNet.Running;
using System;
using System.Linq;
using System.Reflection;
namespace Ben.Demystifier.Benchmarks
{
public static class Program
{
private const string BenchmarkSuffix = "Tests";
public static void Main(string[] args)
{
var benchmarks = Assembly.GetEntryAssembly()
.DefinedTypes.Where(t => t.Name.EndsWith(BenchmarkSuffix))
.ToDictionary(t => t.Name.Substring(0, t.Name.Length - BenchmarkSuffix.Length), t => t, StringComparer.OrdinalIgnoreCase);
if (args.Length > 0 && args[0].Equals("all", StringComparison.OrdinalIgnoreCase))
{
Console.WriteLine("Running full benchmarks suite");
benchmarks.Select(pair => pair.Value).ToList().ForEach(action => BenchmarkRunner.Run(action));
return;
}
if (args.Length == 0 || !benchmarks.ContainsKey(args[0]))
{
Console.WriteLine("Please, select benchmark, list of available:");
benchmarks
.Select(pair => pair.Key)
.ToList()
.ForEach(Console.WriteLine);
Console.WriteLine("All");
return;
}
BenchmarkRunner.Run(benchmarks[args[0]]);
Console.Read();
}
}
internal class Config : ManualConfig
{
public Config() => Add(new MemoryDiagnoser());
}
}