github.com/xtls/xray-core@v1.8.12-0.20240518155711-3168d27b0bdb/common/mux/frame_test.go (about)

     1  package mux_test
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/xtls/xray-core/common"
     7  	"github.com/xtls/xray-core/common/buf"
     8  	"github.com/xtls/xray-core/common/mux"
     9  	"github.com/xtls/xray-core/common/net"
    10  )
    11  
    12  func BenchmarkFrameWrite(b *testing.B) {
    13  	frame := mux.FrameMetadata{
    14  		Target:        net.TCPDestination(net.DomainAddress("www.example.com"), net.Port(80)),
    15  		SessionID:     1,
    16  		SessionStatus: mux.SessionStatusNew,
    17  	}
    18  	writer := buf.New()
    19  	defer writer.Release()
    20  
    21  	for i := 0; i < b.N; i++ {
    22  		common.Must(frame.WriteTo(writer))
    23  		writer.Clear()
    24  	}
    25  }