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

#67 Functions for unpacking based on byte arrays #71

Merged
merged 14 commits into from
Aug 27, 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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@
*.suo
*.user
*.sln.docstates
.idea
.vs

# Build results
DbcParserLib/obj/
DbcParserLib/bin/
DbcParserLib.Tests/obj/
DbcParserLib.Tests/bin/
DbcParserLib.Benchmarks/obj/
DbcParserLib.Benchmarks/bin/
Demo/obj/
Demo/bin/

Expand Down
12 changes: 9 additions & 3 deletions DbcParser.sln
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.31515.178
# Visual Studio Version 17
VisualStudioVersion = 17.9.34607.119
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DbcParserLib", "DbcParserLib\DbcParserLib.csproj", "{82DD10F6-784A-4D87-B117-FB910E84D175}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Demo", "Demo\Demo.csproj", "{9CA98991-90EF-4E86-BCA6-372EF2AE471E}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DbcParserLib.Tests", "DbcParserLib.Tests\DbcParserLib.Tests.csproj", "{0FE933E2-4870-49BD-9A9A-931F30730D82}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DbcParserLib.Tests", "DbcParserLib.Tests\DbcParserLib.Tests.csproj", "{0FE933E2-4870-49BD-9A9A-931F30730D82}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DbcParserLib.Benchmarks", "DbcParserLib.Benchmarks\DbcParserLib.Benchmarks.csproj", "{0B3323E7-FEC3-4606-9012-C6166D941CCC}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand All @@ -27,6 +29,10 @@ Global
{0FE933E2-4870-49BD-9A9A-931F30730D82}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0FE933E2-4870-49BD-9A9A-931F30730D82}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0FE933E2-4870-49BD-9A9A-931F30730D82}.Release|Any CPU.Build.0 = Release|Any CPU
{0B3323E7-FEC3-4606-9012-C6166D941CCC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0B3323E7-FEC3-4606-9012-C6166D941CCC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0B3323E7-FEC3-4606-9012-C6166D941CCC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0B3323E7-FEC3-4606-9012-C6166D941CCC}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
19 changes: 19 additions & 0 deletions DbcParserLib.Benchmarks/DbcParserLib.Benchmarks.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<IsPackable>false</IsPackable>
<OutputType>Exe</OutputType>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

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

<ItemGroup>
<ProjectReference Include="..\DbcParserLib\DbcParserLib.csproj" />
</ItemGroup>

</Project>
182 changes: 182 additions & 0 deletions DbcParserLib.Benchmarks/PackerBenchmark.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
using DbcParserLib.Model;
using BenchmarkDotNet.Attributes;

namespace DbcParserLib.Tests
{
public class PackerBenchmark
{
private Signal EightByte_BigEndian_Signal1;
private Signal EightByte_BigEndian_Signal2;
private Signal EightByte_BigEndian_Signal3;
private Signal EightByte_BigEndian_Signal4;

private Signal EightByte_LittleEndian_Signal1;
private Signal EightByte_LittleEndian_Signal2;
private Signal EightByte_LittleEndian_Signal3;
private Signal EightByte_LittleEndian_Signal4;

private Signal LittleEndian_Unsigned_NoScale;

[GlobalSetup]
public void SetupSignals()
{
EightByte_BigEndian_Signal1 = new Signal
{
StartBit = 7,
Length = 10,
ValueType = DbcValueType.Unsigned,
ByteOrder = 0,
Factor = 1,
Offset = 0
};

EightByte_BigEndian_Signal2 = new Signal
{
StartBit = 13,
Length = 6,
ValueType = DbcValueType.Unsigned,
ByteOrder = 0,
Factor = 1,
Offset = 0
};

EightByte_BigEndian_Signal3 = new Signal
{
StartBit = 23,
Length = 32,
ValueType = DbcValueType.Unsigned,
ByteOrder = 0,
Factor = 1,
Offset = 0
};

EightByte_BigEndian_Signal4 = new Signal
{
StartBit = 55,
Length = 16,
ValueType = DbcValueType.Unsigned,
ByteOrder = 0,
Factor = 1,
Offset = 0
};

EightByte_LittleEndian_Signal1 = new Signal
{
StartBit = 0,
Length = 10,
ValueType = DbcValueType.Unsigned,
ByteOrder = 1,
Factor = 1,
Offset = 0
};

EightByte_LittleEndian_Signal2 = new Signal
{
StartBit = 10,
Length = 6,
ValueType = DbcValueType.Unsigned,
ByteOrder = 1,
Factor = 1,
Offset = 0
};

EightByte_LittleEndian_Signal3 = new Signal
{
StartBit = 16,
Length = 32,
ValueType = DbcValueType.Unsigned,
ByteOrder = 1,
Factor = 1,
Offset = 0
};

EightByte_LittleEndian_Signal4 = new Signal
{
StartBit = 48,
Length = 16,
ValueType = DbcValueType.Unsigned,
ByteOrder = 1,
Factor = 1,
Offset = 0
};

LittleEndian_Unsigned_NoScale = new Signal
{
StartBit = 0,
Length = 32,
ValueType = DbcValueType.Unsigned,
ByteOrder = 1,
Factor = 1,
Offset = 0
};
}

[Benchmark]
public ulong Pack_8Byte_BigEndian_Uint64()
{
ulong TxMsg = 0;
TxMsg |= Packer.TxSignalPack(0, EightByte_BigEndian_Signal1);
TxMsg |= Packer.TxSignalPack(63, EightByte_BigEndian_Signal2);
TxMsg |= Packer.TxSignalPack(0, EightByte_BigEndian_Signal3);
TxMsg |= Packer.TxSignalPack(ushort.MaxValue, EightByte_BigEndian_Signal4);
return TxMsg;
}

[Benchmark]
public byte[] Pack_8Byte_BigEndian_ByteArray()
{
byte[] TxMsg = new byte[8];
Packer.TxSignalPack(TxMsg, 0, EightByte_BigEndian_Signal1);
Packer.TxSignalPack(TxMsg, 63, EightByte_BigEndian_Signal2);
Packer.TxSignalPack(TxMsg, 0, EightByte_BigEndian_Signal3);
Packer.TxSignalPack(TxMsg, ushort.MaxValue, EightByte_BigEndian_Signal4);
return TxMsg;
}

[Benchmark]
public ulong Pack_8Byte_LittleEndian_Uint64()
{
ulong TxMsg = 0;
TxMsg |= Packer.TxSignalPack(0, EightByte_LittleEndian_Signal1);
TxMsg |= Packer.TxSignalPack(63, EightByte_LittleEndian_Signal2);
TxMsg |= Packer.TxSignalPack(0, EightByte_LittleEndian_Signal3);
TxMsg |= Packer.TxSignalPack(ushort.MaxValue, EightByte_LittleEndian_Signal4);
return TxMsg;
}

[Benchmark]
public byte[] Pack_8Byte_LittleEndian_ByteArray()
{
byte[] TxMsg = new byte[8];
Packer.TxSignalPack(TxMsg, 0, EightByte_LittleEndian_Signal1);
Packer.TxSignalPack(TxMsg, 63, EightByte_LittleEndian_Signal2);
Packer.TxSignalPack(TxMsg, 0, EightByte_LittleEndian_Signal3);
Packer.TxSignalPack(TxMsg, ushort.MaxValue, EightByte_LittleEndian_Signal4);
return TxMsg;
}

[Benchmark]
public ulong Pack_1Signal_Unsigned_NoScale_StatePack()
{
ulong TxMsg = 0;
TxMsg |= Packer.TxStatePack(123, LittleEndian_Unsigned_NoScale);
return TxMsg;
}

[Benchmark]
public ulong Pack_1Signal_Unsigned_NoScale_SignalPack()
{
ulong TxMsg = 0;
TxMsg |= Packer.TxSignalPack(123, LittleEndian_Unsigned_NoScale);
return TxMsg;
}

[Benchmark]
public byte[] Pack_1Signal_Unsigned_NoScale_SignalPackByteArray()
{
byte[] TxMsg = new byte[8];
Packer.TxSignalPack(TxMsg, 123, LittleEndian_Unsigned_NoScale);
return TxMsg;
}
}
}
46 changes: 46 additions & 0 deletions DbcParserLib.Benchmarks/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
using BenchmarkDotNet.Running;
using DbcParserLib.Tests;

var summaryPack = BenchmarkRunner.Run<PackerBenchmark>();

/* Summary => This is pc dependend. The relevant information is the time difference

BenchmarkDotNet v0.14.0, Windows 11 (10.0.22631.3880/23H2/2023Update/SunValley3)
AMD Ryzen 9 5900X, 1 CPU, 24 logical and 12 physical cores
.NET SDK 8.0.200
[Host] : .NET 6.0.32 (6.0.3224.31407), X64 RyuJIT AVX2
DefaultJob : .NET 6.0.32 (6.0.3224.31407), X64 RyuJIT AVX2


| Method | Mean | Error | StdDev |
|-------------------------------------------------- |------------:| ----------:| ----------:|
| Pack_8Byte_BigEndian_Uint64 | 40.5778 ns | 0.3100 ns | 0.2420 ns |
| Pack_8Byte_BigEndian_ByteArray | 126.9214 ns | 2.5612 ns | 2.3958 ns |
| Pack_8Byte_LittleEndian_Uint64 | 12.1883 ns | 0.1173 ns | 0.0980 ns |
| Pack_8Byte_LittleEndian_ByteArray | 100.1948 ns | 0.6864 ns | 0.5359 ns |
| Pack_1Signal_Unsigned_NoScale_StatePack | 0.8825 ns | 0.0081 ns | 0.0068 ns |
| Pack_1Signal_Unsigned_NoScale_SignalPack | 3.0999 ns | 0.0711 ns | 0.0665 ns |
| Pack_1Signal_Unsigned_NoScale_SignalPackByteArray | 49.3012 ns | 0.8965 ns | 0.8386 ns |
*/

var summaryUnpack = BenchmarkRunner.Run<UnpackBenchmark>();

/* Summary => This is pc dependend. The relevant information is the time difference

BenchmarkDotNet v0.14.0, Windows 11 (10.0.22631.3880/23H2/2023Update/SunValley3)
AMD Ryzen 9 5900X, 1 CPU, 24 logical and 12 physical cores
.NET SDK 8.0.200
[Host] : .NET 6.0.32 (6.0.3224.31407), X64 RyuJIT AVX2
DefaultJob : .NET 6.0.32 (6.0.3224.31407), X64 RyuJIT AVX2


| Method | Mean | Error | StdDev |
|------------------------------------------------ |-----------:| ----------:| ----------:|
| Unpack_8Byte_BigEndian_Uint64 | 107.287 ns | 2.1000 ns | 2.0625 ns |
| Unpack_8Byte_BigEndian_ByteArray | 201.915 ns | 4.0086 ns | 4.2892 ns |
| Unpack_8Byte_LittleEndian_Uint64 | 81.062 ns | 0.2072 ns | 0.1617 ns |
| Unpack_8Byte_LittleEndian_ByteArray | 171.328 ns | 3.2070 ns | 3.1497 ns |
| Unpack_1Signal_Unsigned_NoScale_State | 1.077 ns | 0.0037 ns | 0.0029 ns |
| Unpack_1Signal_Unsigned_NoScale_Signal | 20.269 ns | 0.1389 ns | 0.1232 ns |
| Unpack_1Signal_Unsigned_NoScale_SignalByteArray | 62.919 ns | 0.1156 ns | 0.0902 ns |
*/
Loading
Loading