diff --git a/pdu/pdu_test.go b/pdu/pdu_test.go index bea4f09..2f05e53 100644 --- a/pdu/pdu_test.go +++ b/pdu/pdu_test.go @@ -292,7 +292,6 @@ func TestEncodeIntoWithBoundaryValues(t *testing.T) { } } - // region decode func TestDecodeHandlesShortByteSlice(t *testing.T) { var p PDU_HEADER @@ -463,7 +462,26 @@ func BenchmarkEncode(b *testing.B) { } b.ResetTimer() for i := 0; i < b.N; i++ { - p.Encode() + buf, _ := p.Encode() + ByteBufferPool.Put(buf) + } +} + +// These two are effectively the same but there is difference in execution time +// I wonder why... +// I should stop writing benchmarks... +func BenchmarkEncodeWithBufferPool(b *testing.B) { + p := &PDU_HEADER{ + command_length: 16, + command_id: 1, + command_status: 0, + sequence_number: 12345, + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + buf := ByteBufferPool.Get(uint(p.Size())) + p.EncodeInto(buf) + ByteBufferPool.Put(buf) } } @@ -489,4 +507,4 @@ func BenchmarkDecode(b *testing.B) { for i := 0; i < b.N; i++ { p.Decode(data) } -} \ No newline at end of file +}