Skip to content

Commit 150ca35

Browse files
author
Petr Sramek
committed
improvements
1 parent 84c2a73 commit 150ca35

26 files changed

+226
-279
lines changed

PolylineAlgorithm.slnx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,7 @@
1010
<Folder Name="/tests/">
1111
<Project Path="tests/PolylineAlgorithm.Tests/PolylineAlgorithm.Tests.csproj" />
1212
</Folder>
13+
<Folder Name="/utilities/" Id="02ea681e-c7d8-13c7-8484-4ac65e1b71e8">
14+
<Project Path="utilities/PolylineAlgorithm.Utility/PolylineAlgorithm.Utility.csproj" Id="69392841-91d5-4b8d-acdb-dd56c87b3034" />
15+
</Folder>
1316
</Solution>

benchmarks/PolylineAlgorithm.Benchmarks/Internal/ValueProvider.cs

Lines changed: 0 additions & 53 deletions
This file was deleted.

benchmarks/PolylineAlgorithm.Benchmarks/PolylineAlgorithm.Benchmarks.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
<ItemGroup>
2626
<ProjectReference Include="..\..\src\PolylineAlgorithm\PolylineAlgorithm.csproj" />
27+
<ProjectReference Include="..\..\utilities\PolylineAlgorithm.Utility\PolylineAlgorithm.Utility.csproj" />
2728
</ItemGroup>
2829

2930
</Project>

benchmarks/PolylineAlgorithm.Benchmarks/PolylineBenchmark.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ namespace PolylineAlgorithm.Benchmarks;
88
using BenchmarkDotNet.Attributes;
99
using BenchmarkDotNet.Engines;
1010
using PolylineAlgorithm;
11-
using PolylineAlgorithm.Benchmarks.Internal;
11+
using PolylineAlgorithm.Utility;
1212

1313
/// <summary>
1414
/// Benchmarks for the <see cref="PolylineValue"/> struct.

benchmarks/PolylineAlgorithm.Benchmarks/PolylineDecoderBenchmark.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ namespace PolylineAlgorithm.Benchmarks;
88
using BenchmarkDotNet.Attributes;
99
using BenchmarkDotNet.Engines;
1010
using PolylineAlgorithm;
11-
using PolylineAlgorithm.Benchmarks.Internal;
1211
using PolylineAlgorithm.Extensions;
12+
using PolylineAlgorithm.Utility;
1313

1414
/// <summary>
1515
/// Benchmarks for the <see cref="PolylineDecoder"/> class.

benchmarks/PolylineAlgorithm.Benchmarks/PolylineEncoderBenchmark.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ namespace PolylineAlgorithm.Benchmarks;
77

88
using BenchmarkDotNet.Attributes;
99
using PolylineAlgorithm;
10-
using PolylineAlgorithm.Benchmarks.Internal;
10+
using PolylineAlgorithm.Utility;
1111
using System.Collections.Generic;
1212
using System.Threading.Tasks;
1313

benchmarks/PolylineAlgorithm.Comparison.Benchmarks/Internal/ValueProvider.cs

Lines changed: 0 additions & 53 deletions
This file was deleted.

benchmarks/PolylineAlgorithm.Comparison.Benchmarks/PolylineAlgorithm.Comparison.Benchmarks.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
<ItemGroup>
2626
<ProjectReference Include="..\..\src\PolylineAlgorithm\PolylineAlgorithm.csproj" />
27+
<ProjectReference Include="..\..\utilities\PolylineAlgorithm.Utility\PolylineAlgorithm.Utility.csproj" />
2728
</ItemGroup>
2829

2930
</Project>

benchmarks/PolylineAlgorithm.Comparison.Benchmarks/PolylineDecoderBenchmark.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ namespace PolylineAlgorithm.Comparison.Benchmarks;
99
using BenchmarkDotNet.Engines;
1010
using global::PolylineEncoder.Net.Utility;
1111
using PolylineAlgorithm;
12-
using PolylineAlgorithm.Comparison.Benchmarks.Internal;
1312
using PolylineAlgorithm.Extensions;
13+
using PolylineAlgorithm.Utility;
1414
using PolylinerNet;
1515
using PolylineEncoding = Cloudikka.PolylineAlgorithm.Encoding.PolylineEncoding;
1616

@@ -21,8 +21,8 @@ namespace PolylineAlgorithm.Comparison.Benchmarks;
2121
public class PolylineDecoderBenchmark {
2222
private readonly Consumer _consumer = new();
2323

24-
[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)]
25-
public int N;
24+
[Params(1, 25, 50, 100, 250, 500, 1_000, 5_000, 10_000, 25_000, 50_000, 100_000, 500_000, 1_000_000)]
25+
public int Count;
2626

2727
#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.
2828
/// <summary>
@@ -53,8 +53,8 @@ public class PolylineDecoderBenchmark {
5353
/// </summary>
5454
[GlobalSetup]
5555
public void SetupData() {
56-
StringValue = ValueProvider.GetPolyline(N).ToString();
57-
PolylineValue = ValueProvider.GetPolyline(N);
56+
StringValue = ValueProvider.GetPolyline(Count).ToString();
57+
PolylineValue = ValueProvider.GetPolyline(Count);
5858
}
5959

6060
/// <summary>

benchmarks/PolylineAlgorithm.Comparison.Benchmarks/PolylineEncoderBenchmark.cs

Lines changed: 52 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ namespace PolylineAlgorithm.Comparison.Benchmarks;
88
using BenchmarkDotNet.Attributes;
99
using global::PolylineEncoder.Net.Utility;
1010
using PolylineAlgorithm;
11-
using PolylineAlgorithm.Comparison.Benchmarks.Internal;
11+
using PolylineAlgorithm.Utility;
1212
using PolylinerNet;
1313
using System.Collections.Generic;
1414
using System.Threading.Tasks;
@@ -19,21 +19,34 @@ namespace PolylineAlgorithm.Comparison.Benchmarks;
1919
/// </summary>
2020
[RankColumn]
2121
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;
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
}

src/PolylineAlgorithm/Abstraction/ICoordinateConverter`1.cs

Lines changed: 0 additions & 12 deletions
This file was deleted.

0 commit comments

Comments
 (0)