-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #71 from Uight/Functions-for-unpacking-based-on-by…
…te-arrays #67 Functions for unpacking based on byte arrays
- Loading branch information
Showing
8 changed files
with
823 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | | ||
*/ |
Oops, something went wrong.