|
8 | 8 | global using System.Diagnostics; |
9 | 9 | global using System.Reflection; |
10 | 10 | global using System.Runtime.Intrinsics; |
| 11 | +global using System.Runtime.Intrinsics.X86; |
11 | 12 | global using System.Security.Cryptography; |
12 | 13 | global using X86Aes = System.Runtime.Intrinsics.X86.Aes; |
13 | | -using System.Runtime.Intrinsics.X86; |
14 | 14 |
|
15 | 15 | #if DEBUG |
16 | 16 | Console.WriteLine(@"On Debug mode"); |
|
20 | 20 | Console.WriteLine(@"Debugger attached!"); |
21 | 21 | } |
22 | 22 |
|
23 | | -Argument<string> methodsArgument = new(@"method(s)", () => CryptoList.All, @"Methods separated by commas."); |
24 | | -methodsArgument.AddCompletions(CryptoList.All); |
| 23 | +Argument<string> methodsArgument = new(@"method(s)") |
| 24 | +{ |
| 25 | + Description = @"Methods separated by commas.", |
| 26 | + DefaultValueFactory = _ => CryptoList.All |
| 27 | +}; |
| 28 | +methodsArgument.CompletionSources.Add(CryptoList.All); |
| 29 | + |
25 | 30 | foreach (string method in CryptoList.Methods) |
26 | 31 | { |
27 | | - methodsArgument.AddCompletions(method); |
| 32 | + methodsArgument.CompletionSources.Add(method); |
28 | 33 | } |
29 | | -Option<double> secondsOption = new(@"--seconds", () => 3.0, @"Run benchmarks for num seconds."); |
30 | | -secondsOption.AddAlias(@"-s"); |
31 | | -Option<int> bytesOption = new(@"--bytes", () => 8 * 1024, @"Run benchmarks on num-byte buffers."); |
32 | | -bytesOption.AddAlias(@"-b"); |
33 | 34 |
|
34 | | -RootCommand cmd = |
35 | | -[ |
| 35 | +Option<double> secondsOption = new(@"--seconds", @"-s") |
| 36 | +{ |
| 37 | + Description = @"Run benchmarks for num seconds.", |
| 38 | + DefaultValueFactory = _ => 3.0 |
| 39 | +}; |
| 40 | + |
| 41 | +Option<int> bytesOption = new(@"--bytes", @"-b") |
| 42 | +{ |
| 43 | + Description = @"Run benchmarks on num-byte buffers.", |
| 44 | + DefaultValueFactory = _ => 8 * 1024 |
| 45 | +}; |
| 46 | + |
| 47 | +RootCommand cmd = new() |
| 48 | +{ |
36 | 49 | methodsArgument, |
37 | 50 | secondsOption, |
38 | 51 | bytesOption |
39 | | -]; |
| 52 | +}; |
40 | 53 |
|
41 | | -cmd.SetHandler((methods, seconds, bytes) => |
| 54 | +cmd.SetAction(parseResult => |
42 | 55 | { |
| 56 | + string methods = parseResult.GetRequiredValue(methodsArgument); |
| 57 | + double seconds = parseResult.GetRequiredValue(secondsOption); |
| 58 | + int bytes = parseResult.GetRequiredValue(bytesOption); |
| 59 | + |
43 | 60 | Console.WriteLine($@"OS Version: {Environment.OSVersion}"); |
44 | 61 | Console.WriteLine($@".NET Version: {Environment.Version}"); |
45 | 62 | Console.WriteLine($@"App Version: {Assembly.GetExecutingAssembly().GetCustomAttribute<AssemblyInformationalVersionAttribute>()!.InformationalVersion}"); |
|
68 | 85 | Console.WriteLine(); |
69 | 86 |
|
70 | 87 | IEnumerable<string> methodList = methods.Split(',', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries); |
| 88 | + |
71 | 89 | if (methodList.Contains(CryptoList.All, StringComparer.OrdinalIgnoreCase)) |
72 | 90 | { |
73 | 91 | methodList = CryptoList.Methods; |
|
81 | 99 | Console.Write($@"Testing {realMethod}: "); |
82 | 100 |
|
83 | 101 | CryptoTest t = new(bytes, seconds); |
| 102 | + |
84 | 103 | switch (crypto) |
85 | 104 | { |
86 | 105 | case XChaCha20Poly1305Crypto xc20P1305: |
|
100 | 119 | } |
101 | 120 | } |
102 | 121 | } |
103 | | -}, methodsArgument, secondsOption, bytesOption); |
| 122 | +}); |
104 | 123 |
|
105 | | -return cmd.Invoke(args); |
| 124 | +return await cmd.Parse(args).InvokeAsync(); |
0 commit comments