(string[] args)
| 176 | }; |
| 177 | |
| 178 | private static int Main(string[] args) |
| 179 | { |
| 180 | BenchmarkOptions options; |
| 181 | try |
| 182 | { |
| 183 | options = BenchmarkOptions.Parse(args); |
| 184 | } |
| 185 | catch (Exception ex) |
| 186 | { |
| 187 | Console.Error.WriteLine($"error: {ex.Message}"); |
| 188 | PrintUsage(); |
| 189 | return 1; |
| 190 | } |
| 191 | |
| 192 | if (options.ShowHelp) |
| 193 | { |
| 194 | PrintUsage(); |
| 195 | return 0; |
| 196 | } |
| 197 | |
| 198 | List<BenchmarkCase> cases; |
| 199 | try |
| 200 | { |
| 201 | options.ValidateSchemaMismatch(); |
| 202 | cases = BuildBenchmarkCases(options); |
| 203 | } |
| 204 | catch (Exception ex) |
| 205 | { |
| 206 | Console.Error.WriteLine($"failed to build benchmarks: {ex}"); |
| 207 | return 1; |
| 208 | } |
| 209 | |
| 210 | if (cases.Count == 0) |
| 211 | { |
| 212 | Console.Error.WriteLine("no benchmark cases selected"); |
| 213 | return 1; |
| 214 | } |
| 215 | |
| 216 | Console.WriteLine("=== Fory C# Benchmark ==="); |
| 217 | Console.WriteLine($"Cases: {cases.Count}"); |
| 218 | Console.WriteLine($"Warmup: {options.WarmupSeconds.ToString("F2", CultureInfo.InvariantCulture)}s"); |
| 219 | Console.WriteLine($"Duration: {options.DurationSeconds.ToString("F2", CultureInfo.InvariantCulture)}s"); |
| 220 | Console.WriteLine($"Schema mismatch: {options.SchemaMismatch}"); |
| 221 | Console.WriteLine(); |
| 222 | |
| 223 | List<BenchmarkResult> results = new(cases.Count); |
| 224 | foreach (BenchmarkCase benchmarkCase in cases) |
| 225 | { |
| 226 | Console.WriteLine($"Running {benchmarkCase.Serializer}/{benchmarkCase.DataType}/{benchmarkCase.Operation}..."); |
| 227 | BenchmarkResult result = RunBenchmarkCase(benchmarkCase, options.WarmupSeconds, options.DurationSeconds); |
| 228 | results.Add(result); |
| 229 | } |
| 230 | |
| 231 | BenchmarkOutput output = new( |
| 232 | GeneratedAtUtc: DateTime.UtcNow.ToString("O", CultureInfo.InvariantCulture), |
| 233 | RuntimeVersion: Environment.Version.ToString(), |
| 234 | OsDescription: RuntimeInformation.OSDescription, |
| 235 | OsArchitecture: RuntimeInformation.OSArchitecture.ToString(), |
nothing calls this directly
no test coverage detected