Skip to content

Commit

Permalink
BenchmarkSwitcher used instead of self-baken solution
Browse files Browse the repository at this point in the history
  • Loading branch information
gfoidl committed Apr 18, 2018
1 parent 9db16cf commit bf00c42
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 66 deletions.
61 changes: 3 additions & 58 deletions perf/gfoidl.Stochastics.Benchmarks/Program.cs
Original file line number Diff line number Diff line change
@@ -1,68 +1,13 @@
using System;
using System.Diagnostics;
using System.Linq;
using System.Numerics;
using System.Reflection;
using BenchmarkDotNet.Running;

namespace gfoidl.Stochastics.Benchmarks
{
static class Program
{
static void Main(string[] args)
{
if (args.Length != 1)
{
Console.WriteLine("one and only arg has to be name of benchmark");
PrintAvailableBenchmarks();
Environment.Exit(1);
}

Console.WriteLine($"{nameof(Vector.IsHardwareAccelerated)}: {Vector.IsHardwareAccelerated}");

string type = args[0];
IBenchmark benchmark = GetBenchmark(type);

if (benchmark == null)
{
Console.WriteLine($"unknown benchmark '{type}'");
PrintAvailableBenchmarks();
Environment.Exit(2);
}

benchmark.Run();

if (Debugger.IsAttached)
{
Console.WriteLine("\nEnd.");
Console.ReadKey();
}
}
//---------------------------------------------------------------------
private static IBenchmark GetBenchmark(string type)
{
Assembly assembly = typeof(Program).Assembly;

Type benchmarkType = assembly
.DefinedTypes
.FirstOrDefault(t => typeof(IBenchmark).IsAssignableFrom(t) && t.Name == type);

if (benchmarkType == null) return null;

return Activator.CreateInstance(benchmarkType) as IBenchmark;
}
//---------------------------------------------------------------------
private static void PrintAvailableBenchmarks()
{
Assembly assembly = typeof(Program).Assembly;

var types = assembly
.DefinedTypes
.Where(t => typeof(IBenchmark).IsAssignableFrom(t) && t != typeof(IBenchmark))
.OrderBy(t => t.Name);

Console.WriteLine("\nAvailable benchmarks:");
foreach (Type type in types)
Console.WriteLine($"\t{type.Name}");
var switcher = BenchmarkSwitcher.FromAssembly(typeof(Program).Assembly);
switcher.Run(args);
}
}
}

This file was deleted.

0 comments on commit bf00c42

Please sign in to comment.