|
14 | 14 | using Neo.VM.Benchmark; |
15 | 15 | using System.Reflection; |
16 | 16 |
|
17 | | -// Flag to determine if running benchmark or running methods |
18 | | -// If `NEO_VM_BENCHMARK` environment variable is set, run benchmark no matter. |
19 | | -var runBenchmark = true; |
20 | | - |
21 | 17 | // Define the benchmark or execute class |
22 | | -var benchmarkType = typeof(Benchmarks_PoCs); |
23 | | - |
24 | | -/* |
25 | | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
26 | | - | | |
27 | | - | DO NOT MODIFY THE CODE BELOW | |
28 | | - | | |
29 | | - | All configuration should be done above this line | |
30 | | - | | |
31 | | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
32 | | -*/ |
33 | | - |
34 | | -// Explanation: |
35 | | -// Benchmark methods must contain no parameters to be valid. |
36 | | -// This is because we need to be able to invoke these methods repeatedly |
37 | | -// without any external input. All necessary data should be set up in the Setup method |
38 | | -// or as properties of the benchmark class. |
39 | | - |
40 | | -// Example: |
41 | | - |
42 | | -// [Benchmark] |
43 | | -// public void BenchmarkMethod() |
44 | | -// { |
45 | | -// // Benchmark code here |
46 | | -// } |
47 | | -if (Environment.GetEnvironmentVariable("NEO_VM_BENCHMARK") != null || runBenchmark) |
| 18 | +if (Environment.GetEnvironmentVariable("NEO_VM_BENCHMARK") != null) |
48 | 19 | { |
49 | | - BenchmarkRunner.Run(benchmarkType); |
| 20 | + BenchmarkSwitcher.FromAssembly(typeof(Program).Assembly).Run(args); |
50 | 21 | } |
51 | 22 | else |
52 | 23 | { |
| 24 | + var benchmarkType = typeof(Benchmarks_PoCs); |
53 | 25 | var instance = Activator.CreateInstance(benchmarkType); |
54 | | - var setupMethod = benchmarkType.GetMethods(BindingFlags.Public | BindingFlags.Instance) |
55 | | - .FirstOrDefault(m => m.GetCustomAttribute<GlobalSetupAttribute>() != null); |
56 | | - if (setupMethod != null) |
57 | | - { |
58 | | - setupMethod.Invoke(instance, null); |
59 | | - } |
| 26 | + benchmarkType.GetMethods(BindingFlags.Public | BindingFlags.Instance) |
| 27 | + .FirstOrDefault(m => m.GetCustomAttribute<GlobalSetupAttribute>() != null)? |
| 28 | + .Invoke(instance, null); // setup |
60 | 29 |
|
61 | | - var methods = benchmarkType.GetMethods(BindingFlags.Public | BindingFlags.Instance); |
| 30 | + var methods = benchmarkType.GetMethods(BindingFlags.Public | BindingFlags.Instance) |
| 31 | + .Where(m => m.DeclaringType == benchmarkType && !m.GetCustomAttributes<GlobalSetupAttribute>().Any()); |
62 | 32 | foreach (var method in methods) |
63 | 33 | { |
64 | | - if (method.DeclaringType == benchmarkType && !method.GetCustomAttributes<GlobalSetupAttribute>().Any()) |
65 | | - { |
66 | | - method.Invoke(instance, null); |
67 | | - } |
| 34 | + method.Invoke(instance, null); |
68 | 35 | } |
69 | 36 | } |
0 commit comments