From 3d7702f1c621e58379b866ea3e7c442f2259ae5f Mon Sep 17 00:00:00 2001 From: PhatPhuckDave Date: Wed, 24 Jul 2024 11:15:35 +0200 Subject: [PATCH 1/2] Add pdu benchmarks --- pdu/pdu_test.go | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/pdu/pdu_test.go b/pdu/pdu_test.go index f3e6561..bea4f09 100644 --- a/pdu/pdu_test.go +++ b/pdu/pdu_test.go @@ -450,3 +450,43 @@ func TestSizeReturns16(t *testing.T) { t.Errorf("Expected size to be 16, got %d", p.Size()) } } + +// region benchmarks + +// With buffer pool +func BenchmarkEncode(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++ { + p.Encode() + } +} + +// Without buffer pool +func BenchmarkEncodeInto(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 := make([]uint8, 16) + p.EncodeInto(&buf) + } +} + +func BenchmarkDecode(b *testing.B) { + p := &PDU_HEADER{} + data := []uint8{0, 0, 0, 16, 0, 0, 0, 1, 0, 0, 0, 2, 0, 0, 0, 3} + b.ResetTimer() + for i := 0; i < b.N; i++ { + p.Decode(data) + } +} \ No newline at end of file From 7faa683237a04c069efef6642fc86caa4e33a710 Mon Sep 17 00:00:00 2001 From: PhatPhuckDave Date: Wed, 24 Jul 2024 11:16:57 +0200 Subject: [PATCH 2/2] Print first date then commit hash for benchmark results --- benchmark/benchmark.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/benchmark/benchmark.go b/benchmark/benchmark.go index 49e9ca4..6878535 100644 --- a/benchmark/benchmark.go +++ b/benchmark/benchmark.go @@ -31,7 +31,7 @@ func main() { } now := time.Now().Format(time.DateOnly) - resultFile := path.Join(".", "results", head+"_"+now+".txt") + resultFile := path.Join(".", "results", now+"_"+head+".txt") log.Printf("Writing results to %s", resultFile) outFile, err := os.Create(resultFile) if err != nil {