Program.cs 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. using System.Collections.Generic;
  2. using System.Linq;
  3. using System.Reflection;
  4. using BenchmarkDotNet.Attributes;
  5. using BenchmarkDotNet.Configs;
  6. using BenchmarkDotNet.Running;
  7. namespace Avalonia.Benchmarks
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. // Use reflection for a more maintainable way of creating the benchmark switcher,
  14. // Benchmarks are listed in namespace order first (e.g. BenchmarkDotNet.Samples.CPU,
  15. // BenchmarkDotNet.Samples.IL, etc) then by name, so the output is easy to understand
  16. var benchmarks = Assembly.GetExecutingAssembly().GetTypes()
  17. .Where(t => t.GetMethods(BindingFlags.Instance | BindingFlags.Public)
  18. .Any(m => m.GetCustomAttributes(typeof(BenchmarkAttribute), false).Any()))
  19. .OrderBy(t => t.Namespace)
  20. .ThenBy(t => t.Name)
  21. .ToArray();
  22. var benchmarkSwitcher = new BenchmarkSwitcher(benchmarks);
  23. IConfig config = null;
  24. if (args.Contains("--debug"))
  25. {
  26. config = new DebugInProcessConfig();
  27. var a = new List<string>(args);
  28. a.Remove("--debug");
  29. args = a.ToArray();
  30. }
  31. benchmarkSwitcher.Run(args, config);
  32. }
  33. }
  34. }