Skip to content

Commit 4339c10

Browse files
sramekpetePetr Sramek
andauthored
added benchmarks (#16)
* added benchmarks * removed not implemented V3 encode implementation benchmark --------- Co-authored-by: Petr Sramek <petr.sramek@outlook.cz>
1 parent e2ea1fa commit 4339c10

File tree

9 files changed

+626
-1
lines changed

9 files changed

+626
-1
lines changed

DropoutCoder.PolylineAlgorithm.sln

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,19 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{576FEFFC
1010
EndProject
1111
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "nuget", "nuget", "{7F9807A1-01FF-40C3-9342-3F3F35D632DA}"
1212
ProjectSection(SolutionItems) = preProject
13-
.\nuget\DropoutCoder.PolylineAlgorithm.nuspec = .\nuget\DropoutCoder.PolylineAlgorithm.nuspec
13+
nuget\DropoutCoder.PolylineAlgorithm.nuspec = nuget\DropoutCoder.PolylineAlgorithm.nuspec
1414
EndProjectSection
1515
EndProject
1616
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DropoutCoder.PolylineAlgorithm.Tests", "tests\DropoutCoder.PolylineAlgorithm.Tests.csproj", "{30324A08-AA42-425D-87DA-8F9C6AF60454}"
1717
EndProject
1818
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "docs", "docs", "{C13E31F9-B8EF-4915-A1C8-BC33F6431EB9}"
1919
EndProject
20+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "benchmarks", "benchmarks", "{33C03F16-4313-4579-87E6-65892AF21D7D}"
21+
EndProject
22+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DropoutCoder.PolylineAlgorithm.Benchmarks", "benchmarks\DropoutCoder.PolylineAlgorithm.Benchmarks\DropoutCoder.PolylineAlgorithm.Benchmarks.csproj", "{9C7CBAD5-415B-4589-86E1-01C849F9C56C}"
23+
EndProject
24+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DropoutCoder.PolylineAlgorithm.Implementation.Benchmarks", "benchmarks\DropoutCoder.PolylineAlgorithm.Implementation.Benchmarks\DropoutCoder.PolylineAlgorithm.Implementation.Benchmarks.csproj", "{D9F175EA-6F4C-4BFF-AB1D-5F45324B6C1B}"
25+
EndProject
2026
Global
2127
GlobalSection(SolutionConfigurationPlatforms) = preSolution
2228
Debug|Any CPU = Debug|Any CPU
@@ -31,13 +37,23 @@ Global
3137
{30324A08-AA42-425D-87DA-8F9C6AF60454}.Debug|Any CPU.Build.0 = Debug|Any CPU
3238
{30324A08-AA42-425D-87DA-8F9C6AF60454}.Release|Any CPU.ActiveCfg = Release|Any CPU
3339
{30324A08-AA42-425D-87DA-8F9C6AF60454}.Release|Any CPU.Build.0 = Release|Any CPU
40+
{9C7CBAD5-415B-4589-86E1-01C849F9C56C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
41+
{9C7CBAD5-415B-4589-86E1-01C849F9C56C}.Debug|Any CPU.Build.0 = Debug|Any CPU
42+
{9C7CBAD5-415B-4589-86E1-01C849F9C56C}.Release|Any CPU.ActiveCfg = Release|Any CPU
43+
{9C7CBAD5-415B-4589-86E1-01C849F9C56C}.Release|Any CPU.Build.0 = Release|Any CPU
44+
{D9F175EA-6F4C-4BFF-AB1D-5F45324B6C1B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
45+
{D9F175EA-6F4C-4BFF-AB1D-5F45324B6C1B}.Debug|Any CPU.Build.0 = Debug|Any CPU
46+
{D9F175EA-6F4C-4BFF-AB1D-5F45324B6C1B}.Release|Any CPU.ActiveCfg = Release|Any CPU
47+
{D9F175EA-6F4C-4BFF-AB1D-5F45324B6C1B}.Release|Any CPU.Build.0 = Release|Any CPU
3448
EndGlobalSection
3549
GlobalSection(SolutionProperties) = preSolution
3650
HideSolutionNode = FALSE
3751
EndGlobalSection
3852
GlobalSection(NestedProjects) = preSolution
3953
{882322A6-E758-4662-8D1C-7C555C8FC3F2} = {51C886AF-D610-48A4-9D73-2DEB38742801}
4054
{30324A08-AA42-425D-87DA-8F9C6AF60454} = {576FEFFC-B624-40C3-A8AF-4E5233802EA0}
55+
{9C7CBAD5-415B-4589-86E1-01C849F9C56C} = {33C03F16-4313-4579-87E6-65892AF21D7D}
56+
{D9F175EA-6F4C-4BFF-AB1D-5F45324B6C1B} = {33C03F16-4313-4579-87E6-65892AF21D7D}
4157
EndGlobalSection
4258
GlobalSection(ExtensibilityGlobals) = postSolution
4359
SolutionGuid = {93A268DC-0947-4FBB-B495-DDAD4B013D82}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net8.0</TargetFramework>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
<Nullable>enable</Nullable>
8+
</PropertyGroup>
9+
10+
<ItemGroup>
11+
<PackageReference Include="BenchmarkDotNet" Version="0.13.11" />
12+
</ItemGroup>
13+
14+
<ItemGroup>
15+
<ProjectReference Include="..\..\src\DropoutCoder.PolylineAlgorithm.csproj" />
16+
</ItemGroup>
17+
18+
</Project>
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
namespace DropoutCoder.PolylineAlgorithm.Benchmarks
2+
{
3+
using BenchmarkDotNet.Attributes;
4+
using BenchmarkDotNet.Engines;
5+
using DropoutCoder.PolylineAlgorithm.Encoding;
6+
7+
[MemoryDiagnoser]
8+
[MarkdownExporter]
9+
public class PolylineEncodingBenchmark
10+
{
11+
private Consumer _consumer = new Consumer();
12+
13+
[Params(10_000, 100_000, 1_000_000, Priority = 2)]
14+
public int N;
15+
16+
public IEnumerable<(double, double)> Coordinates;
17+
18+
public PolylineEncoding Encoding { get; private set; }
19+
20+
public string Polyline;
21+
22+
[GlobalSetup]
23+
public void Setup()
24+
{
25+
Encoding = new PolylineEncoding();
26+
Coordinates = new[] { (42.88895, -100.30630), (44.91513, 19.22495), (20.40244, 7.97495), (-15.52130, -63.74380), (-78.95116, -72.18130), (38.63072, 88.13120), (60.81071, 151.41245), (-58.20769, -173.43130), (59.40939, 83.91245), (-58.20769, 61.41245), (-20.86278, -119.99380), (34.10374, -150.93130), (-71.15367, 31.88120), (-72.04138, -153.74380), (-49.99635, -107.33755), (76.12614, 135.94370), (70.05664, 41.72495), (63.43879, -77.80630), (13.68456, -90.46255), (-75.90519, -7.49380), (74.71112, -127.02505), (-66.61109, 17.81870), (-49.08384, 37.50620) };
27+
Polyline = "}vwdGjafcRsvjKi}pxUhsrtCngtcAjjgzEdqvtLrscbKj}nr@wetlUc`nq]}_kfCyrfaK~wluUl`u}|@wa{lUmmuap@va{lU~oihCu||bF`|era@wsnnIjny{DxamaScqxza@dklDf{}kb@mtpeCavfzGqhx`Wyzzkm@jm`d@dba~Pppkg@h}pxU|rtnHp|flA|~xaPuykyN}fhv[h}pxUx~p}Ymx`sZih~iB{edwB";
28+
}
29+
30+
[Benchmark]
31+
public void Decode() => Encoding
32+
.Decode(Polyline)
33+
.Consume(_consumer);
34+
35+
[Benchmark]
36+
public void Encode() => Encoding
37+
.Encode(Coordinates)
38+
.Consume(_consumer);
39+
}
40+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
namespace DropoutCoder.PolylineAlgorithm.Benchmarks
2+
{
3+
using BenchmarkDotNet.Running;
4+
5+
internal class Program
6+
{
7+
static void Main(string[] args)
8+
{
9+
BenchmarkRunner
10+
.Run<PolylineEncodingBenchmark>();
11+
}
12+
}
13+
}
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
//
2+
// Copyright (c) Petr Šrámek. All rights reserved.
3+
// Licensed under the MIT License. See LICENSE file in the project root for full license information.
4+
//
5+
6+
namespace DropoutCoder.PolylineAlgorithm.Implementation.Benchmarks
7+
{
8+
/// <summary>
9+
/// Defines global constant values
10+
/// </summary>
11+
internal static class Constants
12+
{
13+
#region Constants
14+
15+
/// <summary>
16+
/// Defines the coordinate precision
17+
/// </summary>
18+
public const double Precision = 1E5;
19+
20+
/// <summary>
21+
/// Defines the shift length
22+
/// </summary>
23+
public const int ShiftLength = 5;
24+
25+
#endregion
26+
27+
/// <summary>
28+
/// Defines ASCII characters constant values
29+
/// </summary>
30+
internal static class ASCII
31+
{
32+
#region Constants
33+
34+
/// <summary>
35+
/// Defines the ASCII Question Mark
36+
/// </summary>
37+
public const int QuestionMark = 63;
38+
39+
/// <summary>
40+
/// Defines the ASCII Space
41+
/// </summary>
42+
public const int Space = 32;
43+
44+
/// <summary>
45+
/// Defines the ASCII Unit Separator
46+
/// </summary>
47+
public const int UnitSeparator = 31;
48+
49+
#endregion
50+
}
51+
52+
/// <summary>
53+
/// Defines coordinates constant values
54+
/// </summary>
55+
internal static class Coordinate
56+
{
57+
#region Constants
58+
59+
/// <summary>
60+
/// Defines the maximum value for latitude
61+
/// </summary>
62+
public const int MaxLatitude = 90;
63+
64+
/// <summary>
65+
/// Defines the maximum value for longitude
66+
/// </summary>
67+
public const int MaxLongitude = 180;
68+
69+
/// <summary>
70+
/// Defines the minimum value for latitude
71+
/// </summary>
72+
public const int MinLatitude = -MaxLatitude;
73+
74+
/// <summary>
75+
/// Defines the minimum value for longitude
76+
/// </summary>
77+
public const int MinLongitude = -MaxLongitude;
78+
79+
#endregion
80+
}
81+
}
82+
}

0 commit comments

Comments
 (0)