|
1 | | -using BenchmarkDotNet.Attributes; |
2 | | -using BenchmarkDotNet.Running; |
| 1 | +using BenchmarkDotNet.Running; |
3 | 2 | using System; |
4 | | -using System.Text.Json; |
| 3 | +using NetJSON.Benchmark.Net5_0.Models; |
| 4 | +using static System.Console; |
5 | 5 |
|
6 | 6 | namespace NetJSON.Benchmark.Net5_0 |
7 | 7 | { |
8 | | - public class SimpleObject |
9 | | - { |
10 | | - public string Name { get; set; } |
11 | | - public int ID { get; set; } |
12 | | - } |
13 | | - |
14 | | - public class SimpleObjectBenchmark |
15 | | - { |
16 | | - private readonly SimpleObject obj; |
17 | | - |
18 | | - public SimpleObjectBenchmark() |
19 | | - { |
20 | | - obj = new SimpleObject { ID = 10, Name = "Performance" }; |
21 | | - } |
22 | | - |
23 | | - [Benchmark] |
24 | | - public string NetJson() => NetJSON.Serialize(obj); |
25 | | - |
26 | | - [Benchmark] |
27 | | - public string MicrosoftJson() => JsonSerializer.Serialize(obj); |
28 | | - |
29 | | - [Benchmark] |
30 | | - public byte[] FastestUtf8Json() => Utf8Json.JsonSerializer.Serialize(obj); |
31 | | - } |
32 | | - |
33 | | - class Program |
| 8 | + static class Program |
34 | 9 | { |
35 | 10 | static void Main(string[] args) |
36 | 11 | { |
37 | | - var summary = BenchmarkRunner.Run<SimpleObjectBenchmark>(); |
| 12 | + WriteLine("1. Simple object"); |
| 13 | + WriteLine("2. GUID"); |
| 14 | + WriteLine("3. Int32 values"); |
| 15 | + WriteLine("4. Single values"); |
| 16 | + WriteLine("5. Double values"); |
| 17 | + WriteLine("6. String dictionary"); |
| 18 | + WriteLine("7. String-object dictionary"); |
| 19 | + WriteLine("8. Int32-object"); |
| 20 | + WriteLine("9. String-object"); |
| 21 | + WriteLine("Type the benchmark number and press Enter key: "); |
| 22 | + if (Int32.TryParse(ReadLine(), out int index)) { |
| 23 | + switch (index) { |
| 24 | + case 1: |
| 25 | + BenchmarkRunner.Run<SimpleObjectBenchmark>(); |
| 26 | + return; |
| 27 | + case 2: |
| 28 | + BenchmarkRunner.Run<GuidBenchmark>(); |
| 29 | + return; |
| 30 | + case 3: |
| 31 | + BenchmarkRunner.Run<Int32ArrayBenchmark>(); |
| 32 | + return; |
| 33 | + case 4: |
| 34 | + BenchmarkRunner.Run<SingleArrayBenchmark>(); |
| 35 | + return; |
| 36 | + case 5: |
| 37 | + BenchmarkRunner.Run<DoubleArrayBenchmark>(); |
| 38 | + return; |
| 39 | + case 6: |
| 40 | + BenchmarkRunner.Run<StringDictionaryBenchmark>(); |
| 41 | + return; |
| 42 | + case 7: |
| 43 | + BenchmarkRunner.Run<StringObjectDictionaryBenchmark>(); |
| 44 | + return; |
| 45 | + case 8: |
| 46 | + BenchmarkRunner.Run<Int32Benchmark>(); |
| 47 | + BenchmarkRunner.Run<BoxedInt32Benchmark>(); |
| 48 | + return; |
| 49 | + case 9: |
| 50 | + BenchmarkRunner.Run<StringObjectBenchmark>(); |
| 51 | + return; |
| 52 | + default: |
| 53 | + break; |
| 54 | + } |
| 55 | + } |
38 | 56 | } |
39 | 57 | } |
40 | 58 | } |
0 commit comments