|
1 |
| -// Copyright (c) Microsoft Corporation. |
| 1 | +// Copyright (c) Microsoft Corporation. |
2 | 2 | // Licensed under the MIT License.
|
3 | 3 |
|
4 | 4 | #if BENCHMARK
|
|
15 | 15 | using System.Diagnostics;
|
16 | 16 | using Microsoft.Extensions.CommandLineUtils;
|
17 | 17 |
|
18 |
| -namespace PSRule.Rules.Azure.Benchmark |
| 18 | +namespace PSRule.Rules.Azure.Benchmark; |
| 19 | + |
| 20 | +internal static class Program |
19 | 21 | {
|
20 |
| - internal static class Program |
| 22 | + private static void Main(string[] args) |
21 | 23 | {
|
22 |
| - private static void Main(string[] args) |
| 24 | + var app = new CommandLineApplication |
23 | 25 | {
|
24 |
| - var app = new CommandLineApplication |
25 |
| - { |
26 |
| - Name = "PSRule for Azure Benchmark", |
27 |
| - Description = "A runner for testing PSRule performance" |
28 |
| - }; |
| 26 | + Name = "PSRule for Azure Benchmark", |
| 27 | + Description = "A runner for testing PSRule performance" |
| 28 | + }; |
29 | 29 |
|
30 | 30 | #if !BENCHMARK
|
31 |
| - // Do profiling |
32 |
| - DebugProfile(app); |
33 |
| - app.Execute(args); |
| 31 | + // Do profiling |
| 32 | + DebugProfile(app); |
| 33 | + app.Execute(args); |
34 | 34 | #endif
|
35 | 35 |
|
36 | 36 | #if BENCHMARK
|
37 |
| - RunProfile(app); |
38 |
| - app.Execute(args); |
| 37 | + RunProfile(app); |
| 38 | + app.Execute(args); |
39 | 39 | #endif
|
40 |
| - } |
| 40 | + } |
41 | 41 |
|
42 | 42 | #if BENCHMARK
|
43 | 43 |
|
44 |
| - private static void RunProfile(CommandLineApplication app) |
| 44 | + private static void RunProfile(CommandLineApplication app) |
| 45 | + { |
| 46 | + var config = ManualConfig.CreateEmpty() |
| 47 | + .AddLogger(ConsoleLogger.Default) |
| 48 | + .AddColumnProvider(DefaultColumnProviders.Instance) |
| 49 | + .AddAnalyser(EnvironmentAnalyser.Default) |
| 50 | + .AddAnalyser(OutliersAnalyser.Default) |
| 51 | + .AddAnalyser(MinIterationTimeAnalyser.Default) |
| 52 | + .AddAnalyser(MultimodalDistributionAnalyzer.Default) |
| 53 | + .AddAnalyser(RuntimeErrorAnalyser.Default) |
| 54 | + .AddAnalyser(ZeroMeasurementAnalyser.Default); |
| 55 | + |
| 56 | + app.Command("benchmark", cmd => |
45 | 57 | {
|
46 |
| - var config = ManualConfig.CreateEmpty() |
47 |
| - .AddLogger(ConsoleLogger.Default) |
48 |
| - .AddColumnProvider(DefaultColumnProviders.Instance) |
49 |
| - .AddAnalyser(EnvironmentAnalyser.Default) |
50 |
| - .AddAnalyser(OutliersAnalyser.Default) |
51 |
| - .AddAnalyser(MinIterationTimeAnalyser.Default) |
52 |
| - .AddAnalyser(MultimodalDistributionAnalyzer.Default) |
53 |
| - .AddAnalyser(RuntimeErrorAnalyser.Default) |
54 |
| - .AddAnalyser(ZeroMeasurementAnalyser.Default); |
55 |
| - |
56 |
| - app.Command("benchmark", cmd => |
| 58 | + var output = cmd.Option("-o | --output", "The path to store report output.", CommandOptionType.SingleValue); |
| 59 | + cmd.OnExecute(() => |
57 | 60 | {
|
58 |
| - var output = cmd.Option("-o | --output", "The path to store report output.", CommandOptionType.SingleValue); |
59 |
| - cmd.OnExecute(() => |
| 61 | + if (output.HasValue()) |
60 | 62 | {
|
61 |
| - if (output.HasValue()) |
62 |
| - { |
63 |
| - config.WithArtifactsPath(output.Value()); |
64 |
| - } |
65 |
| - |
66 |
| - // Do benchmarks |
67 |
| - BenchmarkRunner.Run<PSRule>(config); |
68 |
| - return 0; |
69 |
| - }); |
70 |
| - cmd.HelpOption("-? | -h | --help"); |
| 63 | + config.WithArtifactsPath(output.Value()); |
| 64 | + } |
| 65 | + |
| 66 | + // Do benchmarks |
| 67 | + BenchmarkRunner.Run<PSRule>(config); |
| 68 | + return 0; |
71 | 69 | });
|
72 |
| - app.HelpOption("-? | -h | --help"); |
73 |
| - } |
| 70 | + cmd.HelpOption("-? | -h | --help"); |
| 71 | + }); |
| 72 | + app.HelpOption("-? | -h | --help"); |
| 73 | + } |
74 | 74 |
|
75 | 75 | #endif
|
76 | 76 |
|
77 |
| - private const int DebugIterations = 100; |
| 77 | + private const int DebugIterations = 100; |
78 | 78 |
|
79 |
| - private static void DebugProfile(CommandLineApplication app) |
| 79 | + private static void DebugProfile(CommandLineApplication app) |
| 80 | + { |
| 81 | + app.Command("benchmark", cmd => |
80 | 82 | {
|
81 |
| - app.Command("benchmark", cmd => |
| 83 | + cmd.OnExecute(() => |
82 | 84 | {
|
83 |
| - cmd.OnExecute(() => |
84 |
| - { |
85 |
| - Console.WriteLine("Press ENTER to start."); |
86 |
| - Console.ReadLine(); |
87 |
| - RunDebug(); |
88 |
| - return 0; |
89 |
| - }); |
| 85 | + Console.WriteLine("Press ENTER to start."); |
| 86 | + Console.ReadLine(); |
| 87 | + RunDebug(); |
| 88 | + return 0; |
90 | 89 | });
|
91 |
| - } |
| 90 | + }); |
| 91 | + } |
92 | 92 |
|
93 |
| - private static void RunDebug() |
94 |
| - { |
95 |
| - var profile = new PSRule(); |
96 |
| - profile.Prepare(); |
| 93 | + private static void RunDebug() |
| 94 | + { |
| 95 | + var profile = new PSRule(); |
| 96 | + profile.Prepare(); |
97 | 97 |
|
98 |
| - ProfileBlock(); |
99 |
| - for (var i = 0; i < DebugIterations; i++) |
100 |
| - profile.Template(); |
| 98 | + ProfileBlock(); |
| 99 | + for (var i = 0; i < DebugIterations; i++) |
| 100 | + profile.Template(); |
101 | 101 |
|
102 |
| - for (var i = 0; i < DebugIterations; i++) |
103 |
| - profile.PropertyCopyLoop(); |
| 102 | + for (var i = 0; i < DebugIterations; i++) |
| 103 | + profile.PropertyCopyLoop(); |
104 | 104 |
|
105 |
| - for (var i = 0; i < DebugIterations; i++) |
106 |
| - profile.UserDefinedFunctions(); |
107 |
| - } |
| 105 | + for (var i = 0; i < DebugIterations; i++) |
| 106 | + profile.UserDefinedFunctions(); |
| 107 | + } |
108 | 108 |
|
109 |
| - [DebuggerStepThrough] |
110 |
| - private static void ProfileBlock() |
111 |
| - { |
112 |
| - // Do nothing |
113 |
| - } |
| 109 | + [DebuggerStepThrough] |
| 110 | + private static void ProfileBlock() |
| 111 | + { |
| 112 | + // Do nothing |
114 | 113 | }
|
115 | 114 | }
|
0 commit comments