Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added benchmarks #16

Merged
merged 4 commits into from
Jan 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion DropoutCoder.PolylineAlgorithm.sln
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,19 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{576FEFFC
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "nuget", "nuget", "{7F9807A1-01FF-40C3-9342-3F3F35D632DA}"
ProjectSection(SolutionItems) = preProject
.\nuget\DropoutCoder.PolylineAlgorithm.nuspec = .\nuget\DropoutCoder.PolylineAlgorithm.nuspec
nuget\DropoutCoder.PolylineAlgorithm.nuspec = nuget\DropoutCoder.PolylineAlgorithm.nuspec
EndProjectSection
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DropoutCoder.PolylineAlgorithm.Tests", "tests\DropoutCoder.PolylineAlgorithm.Tests.csproj", "{30324A08-AA42-425D-87DA-8F9C6AF60454}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "docs", "docs", "{C13E31F9-B8EF-4915-A1C8-BC33F6431EB9}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "benchmarks", "benchmarks", "{33C03F16-4313-4579-87E6-65892AF21D7D}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DropoutCoder.PolylineAlgorithm.Benchmarks", "benchmarks\DropoutCoder.PolylineAlgorithm.Benchmarks\DropoutCoder.PolylineAlgorithm.Benchmarks.csproj", "{9C7CBAD5-415B-4589-86E1-01C849F9C56C}"
EndProject
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}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -31,13 +37,23 @@ Global
{30324A08-AA42-425D-87DA-8F9C6AF60454}.Debug|Any CPU.Build.0 = Debug|Any CPU
{30324A08-AA42-425D-87DA-8F9C6AF60454}.Release|Any CPU.ActiveCfg = Release|Any CPU
{30324A08-AA42-425D-87DA-8F9C6AF60454}.Release|Any CPU.Build.0 = Release|Any CPU
{9C7CBAD5-415B-4589-86E1-01C849F9C56C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9C7CBAD5-415B-4589-86E1-01C849F9C56C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9C7CBAD5-415B-4589-86E1-01C849F9C56C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9C7CBAD5-415B-4589-86E1-01C849F9C56C}.Release|Any CPU.Build.0 = Release|Any CPU
{D9F175EA-6F4C-4BFF-AB1D-5F45324B6C1B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D9F175EA-6F4C-4BFF-AB1D-5F45324B6C1B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D9F175EA-6F4C-4BFF-AB1D-5F45324B6C1B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D9F175EA-6F4C-4BFF-AB1D-5F45324B6C1B}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{882322A6-E758-4662-8D1C-7C555C8FC3F2} = {51C886AF-D610-48A4-9D73-2DEB38742801}
{30324A08-AA42-425D-87DA-8F9C6AF60454} = {576FEFFC-B624-40C3-A8AF-4E5233802EA0}
{9C7CBAD5-415B-4589-86E1-01C849F9C56C} = {33C03F16-4313-4579-87E6-65892AF21D7D}
{D9F175EA-6F4C-4BFF-AB1D-5F45324B6C1B} = {33C03F16-4313-4579-87E6-65892AF21D7D}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {93A268DC-0947-4FBB-B495-DDAD4B013D82}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="BenchmarkDotNet" Version="0.13.11" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\DropoutCoder.PolylineAlgorithm.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
namespace DropoutCoder.PolylineAlgorithm.Benchmarks
{
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Engines;
using DropoutCoder.PolylineAlgorithm.Encoding;

[MemoryDiagnoser]
[MarkdownExporter]
public class PolylineEncodingBenchmark
{
private Consumer _consumer = new Consumer();

[Params(10_000, 100_000, 1_000_000, Priority = 2)]
public int N;

public IEnumerable<(double, double)> Coordinates;

Check warning on line 16 in benchmarks/DropoutCoder.PolylineAlgorithm.Benchmarks/PolylineEncodingBenchmark.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable field 'Coordinates' must contain a non-null value when exiting constructor. Consider declaring the field as nullable.

Check warning on line 16 in benchmarks/DropoutCoder.PolylineAlgorithm.Benchmarks/PolylineEncodingBenchmark.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable field 'Coordinates' must contain a non-null value when exiting constructor. Consider declaring the field as nullable.

public PolylineEncoding Encoding { get; private set; }

Check warning on line 18 in benchmarks/DropoutCoder.PolylineAlgorithm.Benchmarks/PolylineEncodingBenchmark.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'Encoding' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

Check warning on line 18 in benchmarks/DropoutCoder.PolylineAlgorithm.Benchmarks/PolylineEncodingBenchmark.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'Encoding' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

public string Polyline;

Check warning on line 20 in benchmarks/DropoutCoder.PolylineAlgorithm.Benchmarks/PolylineEncodingBenchmark.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable field 'Polyline' must contain a non-null value when exiting constructor. Consider declaring the field as nullable.

Check warning on line 20 in benchmarks/DropoutCoder.PolylineAlgorithm.Benchmarks/PolylineEncodingBenchmark.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable field 'Polyline' must contain a non-null value when exiting constructor. Consider declaring the field as nullable.

[GlobalSetup]
public void Setup()
{
Encoding = new PolylineEncoding();
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) };
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";
}

[Benchmark]
public void Decode() => Encoding
.Decode(Polyline)
.Consume(_consumer);

[Benchmark]
public void Encode() => Encoding
.Encode(Coordinates)
.Consume(_consumer);
}
}
13 changes: 13 additions & 0 deletions benchmarks/DropoutCoder.PolylineAlgorithm.Benchmarks/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
namespace DropoutCoder.PolylineAlgorithm.Benchmarks
{
using BenchmarkDotNet.Running;

internal class Program
{
static void Main(string[] args)
{
BenchmarkRunner
.Run<PolylineEncodingBenchmark>();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
//
// Copyright (c) Petr Šrámek. All rights reserved.
// Licensed under the MIT License. See LICENSE file in the project root for full license information.
//

namespace DropoutCoder.PolylineAlgorithm.Implementation.Benchmarks
{
/// <summary>
/// Defines global constant values
/// </summary>
internal static class Constants
{
#region Constants

/// <summary>
/// Defines the coordinate precision
/// </summary>
public const double Precision = 1E5;

/// <summary>
/// Defines the shift length
/// </summary>
public const int ShiftLength = 5;

#endregion

/// <summary>
/// Defines ASCII characters constant values
/// </summary>
internal static class ASCII
{
#region Constants

/// <summary>
/// Defines the ASCII Question Mark
/// </summary>
public const int QuestionMark = 63;

/// <summary>
/// Defines the ASCII Space
/// </summary>
public const int Space = 32;

/// <summary>
/// Defines the ASCII Unit Separator
/// </summary>
public const int UnitSeparator = 31;

#endregion
}

/// <summary>
/// Defines coordinates constant values
/// </summary>
internal static class Coordinate
{
#region Constants

/// <summary>
/// Defines the maximum value for latitude
/// </summary>
public const int MaxLatitude = 90;

/// <summary>
/// Defines the maximum value for longitude
/// </summary>
public const int MaxLongitude = 180;

/// <summary>
/// Defines the minimum value for latitude
/// </summary>
public const int MinLatitude = -MaxLatitude;

/// <summary>
/// Defines the minimum value for longitude
/// </summary>
public const int MinLongitude = -MaxLongitude;

#endregion
}
}
}
Loading
Loading