BenchmarkRunner.cs 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. using BenchmarkDotNet.Attributes;
  2. using BenchmarkDotNet.Configs;
  3. namespace App.OrmRunner
  4. {
  5. class Config : ManualConfig
  6. {
  7. // https://benchmarkdotnet.org/articles/configs/configs.html
  8. public Config()
  9. {
  10. WithOptions(ConfigOptions.DisableOptimizationsValidator);
  11. }
  12. }
  13. [Config(typeof(Config))]
  14. //[Orderer(BenchmarkDotNet.Order.SummaryOrderPolicy.FastestToSlowest)]
  15. [InProcess]
  16. public class BenchmarkRunner
  17. {
  18. //[Params(100)]
  19. public int N = 100;
  20. //[Params(true, false)]
  21. public bool executeQuery = true;
  22. [Params(false, true)]
  23. public bool queryJoin = false;
  24. [Params(10, 100, 1000)]
  25. public int take = 100;
  26. [Params(0, 10)]
  27. public int? skip = 10;
  28. [Params(typeof(Runner_Vitorm), typeof(Runner_EntityFramework))]
  29. public Type runner;
  30. IRunner queryTest;
  31. [GlobalSetup]
  32. public void Setup()
  33. {
  34. queryTest = Activator.CreateInstance(runner) as IRunner;
  35. }
  36. [Benchmark]
  37. public void Run()
  38. {
  39. var config = new RunConfig { repeatCount = N, executeQuery = executeQuery, queryJoin = queryJoin, skip = skip, take = take };
  40. queryTest.Run(config);
  41. }
  42. }
  43. }