BenchmarkRunner.cs 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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.Method)]
  15. [InProcess]
  16. public class BenchmarkRunner
  17. {
  18. //[Params(1, 100)]
  19. public int N = 1;
  20. //[Params(true, false)]
  21. public bool executeQuery = true;
  22. [Params(false, true)]
  23. public bool queryJoin = true;
  24. [Params(1, 1000)]
  25. //[Params(100)]
  26. public int take = 1;
  27. //[Params(0, 10)]
  28. public int? skip = null;
  29. [Params(typeof(Runner_Vitorm), typeof(Runner_EntityFramework), typeof(Runner_SqlSuger))]
  30. public Type runner;
  31. IRunner queryTest;
  32. [GlobalSetup]
  33. public void Setup()
  34. {
  35. queryTest = Activator.CreateInstance(runner) as IRunner;
  36. }
  37. [Benchmark]
  38. public void Run()
  39. {
  40. var config = new RunConfig { repeatCount = N, executeQuery = executeQuery, queryJoin = queryJoin, skip = skip, take = take };
  41. queryTest.Run(config);
  42. }
  43. }
  44. }