Add more benchmarks?
All checks were successful
Run Tests / Test (push) Successful in 25s
Benchmark BufferPool / RunBenchmarks (push) Successful in 28s

This commit is contained in:
2024-07-24 11:32:09 +02:00
parent 7faa683237
commit bed69fbfd3

View File

@@ -292,7 +292,6 @@ func TestEncodeIntoWithBoundaryValues(t *testing.T) {
} }
} }
// region decode // region decode
func TestDecodeHandlesShortByteSlice(t *testing.T) { func TestDecodeHandlesShortByteSlice(t *testing.T) {
var p PDU_HEADER var p PDU_HEADER
@@ -463,7 +462,26 @@ func BenchmarkEncode(b *testing.B) {
} }
b.ResetTimer() b.ResetTimer()
for i := 0; i < b.N; i++ { 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++ { for i := 0; i < b.N; i++ {
p.Decode(data) p.Decode(data)
} }
} }