Skip to content

Commit

Permalink
fix buffer allocs for benchmark (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
Aaronontheweb authored Apr 15, 2024
1 parent 074d4be commit 69b3e61
Showing 1 changed file with 3 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public class Mqtt311ConnectCodecBenchmarks
}
};

private byte[] _writeableBytes;

Check warning on line 45 in benchmarks/TurboMqtt.Core.Benchmarks/Mqtt311/Mqtt311ConnectCodecBenchmarks.cs

View workflow job for this annotation

GitHub Actions / Test-ubuntu-latest

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

Check warning on line 45 in benchmarks/TurboMqtt.Core.Benchmarks/Mqtt311/Mqtt311ConnectCodecBenchmarks.cs

View workflow job for this annotation

GitHub Actions / Test-ubuntu-latest

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

Check warning on line 45 in benchmarks/TurboMqtt.Core.Benchmarks/Mqtt311/Mqtt311ConnectCodecBenchmarks.cs

View workflow job for this annotation

GitHub Actions / Test-windows-latest

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

Check warning on line 45 in benchmarks/TurboMqtt.Core.Benchmarks/Mqtt311/Mqtt311ConnectCodecBenchmarks.cs

View workflow job for this annotation

GitHub Actions / Test-windows-latest

Non-nullable field '_writeableBytes' must contain a non-null value when exiting constructor. Consider declaring the field as nullable.
private ReadOnlyMemory<byte> _encodedConnectPacket;
private int _estimatedConnectPacketSize;
private int _estimatedHeaderSize;
Expand All @@ -52,6 +53,7 @@ public void Setup()
var estimate = MqttPacketSizeEstimator.EstimateMqtt3PacketSize(_connectPacket);
var headerSize =
MqttPacketSizeEstimator.GetPacketLengthHeaderSize(estimate) + 1; // add 1 for the lead byte
_writeableBytes = new byte[estimate + headerSize];
var memory = new Memory<byte>(new byte[estimate + headerSize]);
_encodedConnectPacket = memory;
Mqtt311Encoder.EncodePacket(_connectPacket, ref memory, estimate);
Expand All @@ -64,7 +66,7 @@ public void Setup()
[IterationSetup]
public void IterationSetup()
{
_writeableBuffer = new Memory<byte>(new byte[_estimatedConnectPacketSize + _estimatedHeaderSize]);
_writeableBuffer = new Memory<byte>(_writeableBytes);
}

[Benchmark]
Expand Down

0 comments on commit 69b3e61

Please sign in to comment.