diff --git a/common/turbotunnel/queuepacketconn_test.go b/common/turbotunnel/queuepacketconn_test.go new file mode 100644 index 0000000000000000000000000000000000000000..7889446d200c67bf22979fbfe41b5cd953e685f2 --- /dev/null +++ b/common/turbotunnel/queuepacketconn_test.go @@ -0,0 +1,27 @@ +package turbotunnel + +import ( + "testing" + "time" +) + +type emptyAddr struct{} + +func (_ emptyAddr) Network() string { return "empty" } +func (_ emptyAddr) String() string { return "empty" } + +// Run with -benchmem to see memory allocations. +func BenchmarkQueueIncoming(b *testing.B) { + conn := NewQueuePacketConn(emptyAddr{}, 1*time.Hour) + defer conn.Close() + + b.ResetTimer() + s := 500 + for i := 0; i < b.N; i++ { + // Use a variable for the length to stop the compiler from + // optimizing out the allocation. + p := make([]byte, s) + conn.QueueIncoming(p, emptyAddr{}) + } + b.StopTimer() +}