|
1 | 1 | using BenchmarkDotNet.Attributes; |
2 | 2 | using BenchmarkDotNet.Jobs; |
3 | | -using System; |
4 | 3 |
|
5 | 4 | using System.Collections.Generic; |
6 | | -using System.Security.Cryptography; |
7 | 5 |
|
8 | 6 | namespace GeoJSON.Text.Test.Benchmark |
9 | 7 | { |
10 | | - [SimpleJob(RuntimeMoniker.Net60)] |
| 8 | + [SimpleJob(RuntimeMoniker.Net60, baseline:true)] |
11 | 9 | [SimpleJob(RuntimeMoniker.Net50)] |
12 | 10 | [SimpleJob(RuntimeMoniker.NetCoreApp31)] |
| 11 | + [MemoryDiagnoser] |
13 | 12 | [RPlotExporter] |
14 | 13 | public class BenchmarkSerializeFeatureCollectionLinestring |
15 | 14 | { |
16 | 15 | // GeoJson.NET |
17 | | - private Net.Feature.FeatureCollection featureCollectionGeoJsonNET; |
| 16 | + private Net.Feature.FeatureCollection featureCollectionGeoJsonNET = new Net.Feature.FeatureCollection(); |
18 | 17 |
|
19 | 18 | // GeoJson.Text |
20 | | - private Text.Feature.FeatureCollection featureCollectionGeoJsonTEXT; |
| 19 | + private Text.Feature.FeatureCollection featureCollectionGeoJsonTEXT = new Text.Feature.FeatureCollection(); |
21 | 20 |
|
22 | | - [Params(1000, 10000, 100000)] |
| 21 | + [Params(100000, 1000000)] |
23 | 22 | public int N; |
24 | 23 |
|
25 | | - public BenchmarkSerializeFeatureCollectionLinestring() |
| 24 | + [GlobalSetup] |
| 25 | + public void Setup() |
26 | 26 | { |
27 | | - var featuresNET = new List<Net.Feature.Feature>(); |
28 | | - var featuresTEXT = new List<Text.Feature.Feature>(); |
29 | | - |
| 27 | + var coordinates1 = new double[] { 10, 50 }; |
| 28 | + var coordinates2 = new double[] { 10, 50 }; |
| 29 | + var coordinates3 = new double[] { 10, 50 }; |
| 30 | + var coordinates4 = new double[] { 10, 50 }; |
| 31 | + var line = new List<IEnumerable<double>> { coordinates1, coordinates2, coordinates3, coordinates4 }; |
30 | 32 | for (int i = 0; i< N; i++) |
31 | 33 | { |
32 | | - var lineCoordinates = new List<List<double>> |
33 | | - { |
34 | | - new List<double> |
35 | | - { |
36 | | - -0.26092529296875, |
37 | | - 51.470691106434884 |
38 | | - }, |
39 | | - }; |
40 | | - |
41 | | - var linestringNET = new Net.Geometry.LineString(lineCoordinates); |
42 | | - var linestringTEXT = new Text.Geometry.LineString(lineCoordinates); |
| 34 | + var linestringNET = new Net.Geometry.LineString(line); |
| 35 | + GeoJSON.Net.Feature.Feature featureNET = new Net.Feature.Feature(linestringNET); |
| 36 | + featureCollectionGeoJsonNET.Features.Add(featureNET); |
43 | 37 |
|
44 | | - var featureNET = new Net.Feature.Feature(linestringNET); |
45 | | - var featureTEXT = new Text.Feature.Feature(linestringTEXT); |
46 | | - |
47 | | - featuresNET.Add(featureNET); |
48 | | - featuresTEXT.Add(featureTEXT); |
| 38 | + var linestringTEXT = new Text.Geometry.LineString(line); |
| 39 | + Text.Feature.Feature featureTEXT = new Text.Feature.Feature(linestringTEXT); |
| 40 | + featureCollectionGeoJsonTEXT.Features.Add(featureTEXT); |
49 | 41 | } |
50 | | - |
51 | | - featureCollectionGeoJsonNET = new Net.Feature.FeatureCollection(featuresNET); |
52 | | - featureCollectionGeoJsonTEXT = new Text.Feature.FeatureCollection(featuresTEXT); |
53 | 42 | } |
54 | 43 |
|
55 | 44 | [Benchmark] |
56 | | - public void SerializeNewtonsoft() |
57 | | - { |
58 | | - Newtonsoft.Json.JsonConvert.SerializeObject(featureCollectionGeoJsonNET); |
59 | | - } |
| 45 | + public string SerializeNewtonsoft() => Newtonsoft.Json.JsonConvert.SerializeObject(featureCollectionGeoJsonNET); |
60 | 46 |
|
61 | 47 | [Benchmark] |
62 | | - public void SerializeSystemTextJson() |
63 | | - { |
64 | | - System.Text.Json.JsonSerializer.Serialize(featureCollectionGeoJsonTEXT); |
65 | | - } |
| 48 | + public string SerializeSystemTextJson() => System.Text.Json.JsonSerializer.Serialize(featureCollectionGeoJsonTEXT); |
66 | 49 | } |
67 | 50 | } |
0 commit comments