@@ -8,7 +8,7 @@ namespace PolylineAlgorithm.Comparison.Benchmarks;
88using BenchmarkDotNet . Attributes ;
99using global ::PolylineEncoder . Net . Utility ;
1010using PolylineAlgorithm ;
11- using PolylineAlgorithm . Comparison . Benchmarks . Internal ;
11+ using PolylineAlgorithm . Utility ;
1212using PolylinerNet ;
1313using System . Collections . Generic ;
1414using System . Threading . Tasks ;
@@ -19,21 +19,34 @@ namespace PolylineAlgorithm.Comparison.Benchmarks;
1919/// </summary>
2020[ RankColumn ]
2121public class PolylineEncoderBenchmark {
22- [ Params ( 1 , 10 , 100 , 250 , 500 , 1_000 , 2_500 , 5_000 , 7_500 , 10_000 , 15_000 , 20_000 , 25_000 , 50_000 , 75_000 , 100_000 , 250_000 , 500_000 , 750_000 , 1_000_000 ) ]
23- public int N ;
22+ [ Params ( 1 , 25 , 50 , 100 , 250 , 500 , 1_000 , 5_000 , 10_000 , 25_000 , 50_000 , 100_000 , 500_000 , 1_000_000 ) ]
23+ public int Count ;
2424
2525#pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring as nullable.
2626 /// <summary>
2727 /// Gets the enumeration of coordinates to be encoded.
2828 /// </summary>
29- public static IEnumerable < Coordinate > Enumeration { get ; private set ; }
29+ public static IEnumerable < Coordinate > PolylineAlgorithmEnumeration { get ; private set ; }
3030
3131 /// <summary>
3232 /// Gets the list of coordinates to be encoded.
3333 /// </summary>
34- public static List < Coordinate > List { get ; private set ; }
34+ public static List < Coordinate > PolylineAlgorithmList { get ; private set ; }
35+
36+ /// <summary>
37+ /// Gets the enumeration of coordinates to be encoded.
38+ /// </summary>
39+ public static IEnumerable < ( double , double ) > CloudikkaEnumeration { get ; private set ; }
40+
41+ /// <summary>
42+ /// Gets the list of coordinates to be encoded.
43+ /// </summary>
44+ public List < ( double , double ) > CloudikkaList { get ; private set ; }
45+ public List < PolylinePoint > PolylinerList { get ; private set ; }
46+ public List < Polylines . PolylineCoordinate > PolylinesList { get ; private set ; }
47+ public List < Tuple < double , double > > PolylineUtilityList { get ; private set ; }
48+
3549
36- public static IAsyncEnumerable < Coordinate > AsyncEnumeration { get ; private set ; }
3750#pragma warning restore CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring as nullable.
3851
3952 /// <summary>
@@ -57,82 +70,73 @@ public class PolylineEncoderBenchmark {
5770 /// </summary>
5871 [ GlobalSetup ]
5972 public void SetupData ( ) {
60- Enumeration = ValueProvider . GetCoordinates ( N ) ;
61- List = [ .. Enumeration ] ;
62- AsyncEnumeration = GetAsyncEnumeration ( Enumeration ! ) ;
63- }
64-
65- private async IAsyncEnumerable < Coordinate > GetAsyncEnumeration ( IEnumerable < Coordinate > enumerable ) {
66- foreach ( var item in enumerable ) {
67- yield return await new ValueTask < Coordinate > ( item ) ;
68- }
73+ PolylineAlgorithmEnumeration = ValueProvider . GetCoordinates ( Count ) ;
74+ PolylineAlgorithmList = [ .. PolylineAlgorithmEnumeration ] ;
75+ CloudikkaEnumeration = PolylineAlgorithmEnumeration . Select ( c => ( c . Latitude , c . Longitude ) ) ;
76+ CloudikkaList = [ .. CloudikkaEnumeration ] ;
77+ PolylinerList = PolylineAlgorithmEnumeration . Select ( c => new PolylinePoint ( c . Latitude , c . Longitude ) ) . ToList ( ) ;
78+ PolylinesList = PolylineAlgorithmEnumeration . Select ( c => new Polylines . PolylineCoordinate { Latitude = c . Latitude , Longitude = c . Longitude } ) . ToList ( ) ;
79+ PolylineUtilityList = PolylineAlgorithmEnumeration . Select ( c => new Tuple < double , double > ( c . Latitude , c . Longitude ) ) . ToList ( ) ;
6980 }
7081
7182 /// <summary>
7283 /// Benchmarks the decoding of a polyline from a string.
7384 /// </summary>
85+ [ Benchmark ]
86+ public Polyline PolylineAlgorithm_Encode_Enumeration ( ) {
87+ return PolylineAlgorithm
88+ . Encode ( PolylineAlgorithmEnumeration ) ;
89+ }
90+
7491 [ Benchmark ( Baseline = true ) ]
75- public Polyline PolylineAlgorithm_Encode ( ) {
92+ public Polyline PolylineAlgorithm_Encode_List ( ) {
7693 return PolylineAlgorithm
77- . Encode ( Enumeration ) ;
94+ . Encode ( PolylineAlgorithmList ) ;
7895 }
7996
8097 /// <summary>
8198 /// Benchmarks the decoding of a polyline from a character array.
8299 /// </summary>
83100 [ Benchmark ]
84- public string Cloudikka_Encode ( ) {
101+ public string Cloudikka_Encode_Enumeration ( ) {
85102 return Cloudikka
86- . Encode ( Enumeration . Select ( c => ( c . Latitude , c . Longitude ) ) ) ;
103+ . Encode ( CloudikkaEnumeration ) ;
87104 }
88105
89106 /// <summary>
90- /// Benchmarks the decoding of a polyline from read-only memory .
107+ /// Benchmarks the decoding of a polyline from a character array .
91108 /// </summary>
92109 [ Benchmark ]
93- public void PolylinerNet_Encode ( ) {
94- PolylinerNet
95- . Encode ( [ .. Enumeration . Select ( c => new PolylinePoint ( c . Latitude , c . Longitude ) ) ] ) ;
110+ public string Cloudikka_Encode_List ( ) {
111+ return Cloudikka
112+ . Encode ( CloudikkaList ) ;
96113 }
97114
98115 /// <summary>
99116 /// Benchmarks the decoding of a polyline from read-only memory.
100117 /// </summary>
101118 [ Benchmark ]
102- public string Polylines_Encode ( ) {
103- return Polylines . Polyline
104- . EncodePoints ( Enumeration . Select ( c => new Polylines . PolylineCoordinate { Latitude = c . Latitude , Longitude = c . Longitude } ) ) ;
119+ public string PolylinerNet_Encode_List ( ) {
120+ return PolylinerNet
121+ . Encode ( PolylinerList ) ;
105122 }
106123
124+
107125 /// <summary>
108126 /// Benchmarks the decoding of a polyline from read-only memory.
109127 /// </summary>
110128 [ Benchmark ]
111- public string PolylineUtility_Encode ( ) {
112- return PolylineUtility
113- . Encode ( Enumeration . Select ( c => new Tuple < double , double > ( c . Latitude , c . Longitude ) ) ) ;
129+ public string Polylines_Encode_List ( ) {
130+ return Polylines . Polyline
131+ . EncodePoints ( PolylinesList ) ;
114132 }
115133
116134 /// <summary>
117135 /// Benchmarks the decoding of a polyline from read-only memory.
118136 /// </summary>
119- //[Benchmark]
120- //public void PolylineReader_ReadToEnd() {
121- // PolylineReader reader = new(StringValue);
122-
123- // var result = ReadToEnd(ref reader);
124-
125- // result
126- // .Consume(_consumer);
127-
128- // static IEnumerable<Coordinate> ReadToEnd(ref PolylineReader reader) {
129- // var result = new List<Coordinate>();
130-
131- // while (reader.Read()) {
132- // result.Add(new(reader.Latitude, reader.Longitude));
133- // }
134-
135- // return result;
136- // }
137- //}
137+ [ Benchmark ]
138+ public string PolylineUtility_Encode_List ( ) {
139+ return PolylineUtility
140+ . Encode ( PolylineUtilityList ) ;
141+ }
138142}
0 commit comments