@@ -8,7 +8,7 @@ namespace PolylineAlgorithm.Comparison.Benchmarks;
8
8
using BenchmarkDotNet . Attributes ;
9
9
using global ::PolylineEncoder . Net . Utility ;
10
10
using PolylineAlgorithm ;
11
- using PolylineAlgorithm . Comparison . Benchmarks . Internal ;
11
+ using PolylineAlgorithm . Utility ;
12
12
using PolylinerNet ;
13
13
using System . Collections . Generic ;
14
14
using System . Threading . Tasks ;
@@ -19,21 +19,34 @@ namespace PolylineAlgorithm.Comparison.Benchmarks;
19
19
/// </summary>
20
20
[ RankColumn ]
21
21
public 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 ;
24
24
25
25
#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.
26
26
/// <summary>
27
27
/// Gets the enumeration of coordinates to be encoded.
28
28
/// </summary>
29
- public static IEnumerable < Coordinate > Enumeration { get ; private set ; }
29
+ public static IEnumerable < Coordinate > PolylineAlgorithmEnumeration { get ; private set ; }
30
30
31
31
/// <summary>
32
32
/// Gets the list of coordinates to be encoded.
33
33
/// </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
+
35
49
36
- public static IAsyncEnumerable < Coordinate > AsyncEnumeration { get ; private set ; }
37
50
#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.
38
51
39
52
/// <summary>
@@ -57,82 +70,73 @@ public class PolylineEncoderBenchmark {
57
70
/// </summary>
58
71
[ GlobalSetup ]
59
72
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 ( ) ;
69
80
}
70
81
71
82
/// <summary>
72
83
/// Benchmarks the decoding of a polyline from a string.
73
84
/// </summary>
85
+ [ Benchmark ]
86
+ public Polyline PolylineAlgorithm_Encode_Enumeration ( ) {
87
+ return PolylineAlgorithm
88
+ . Encode ( PolylineAlgorithmEnumeration ) ;
89
+ }
90
+
74
91
[ Benchmark ( Baseline = true ) ]
75
- public Polyline PolylineAlgorithm_Encode ( ) {
92
+ public Polyline PolylineAlgorithm_Encode_List ( ) {
76
93
return PolylineAlgorithm
77
- . Encode ( Enumeration ) ;
94
+ . Encode ( PolylineAlgorithmList ) ;
78
95
}
79
96
80
97
/// <summary>
81
98
/// Benchmarks the decoding of a polyline from a character array.
82
99
/// </summary>
83
100
[ Benchmark ]
84
- public string Cloudikka_Encode ( ) {
101
+ public string Cloudikka_Encode_Enumeration ( ) {
85
102
return Cloudikka
86
- . Encode ( Enumeration . Select ( c => ( c . Latitude , c . Longitude ) ) ) ;
103
+ . Encode ( CloudikkaEnumeration ) ;
87
104
}
88
105
89
106
/// <summary>
90
- /// Benchmarks the decoding of a polyline from read-only memory .
107
+ /// Benchmarks the decoding of a polyline from a character array .
91
108
/// </summary>
92
109
[ 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 ) ;
96
113
}
97
114
98
115
/// <summary>
99
116
/// Benchmarks the decoding of a polyline from read-only memory.
100
117
/// </summary>
101
118
[ 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 ) ;
105
122
}
106
123
124
+
107
125
/// <summary>
108
126
/// Benchmarks the decoding of a polyline from read-only memory.
109
127
/// </summary>
110
128
[ 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 ) ;
114
132
}
115
133
116
134
/// <summary>
117
135
/// Benchmarks the decoding of a polyline from read-only memory.
118
136
/// </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
+ }
138
142
}
0 commit comments