github.com/TeaOSLab/EdgeNode@v1.3.8/internal/conns/map_test_test.go (about) 1 // Copyright 2024 GoEdge CDN goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cn . 2 3 package conns_test 4 5 import ( 6 "github.com/TeaOSLab/EdgeNode/internal/conns" 7 "github.com/TeaOSLab/EdgeNode/internal/utils/testutils" 8 "net" 9 "runtime" 10 "testing" 11 "time" 12 ) 13 14 type testConn struct { 15 net.Conn 16 17 addr net.Addr 18 } 19 20 func (this *testConn) Read(b []byte) (n int, err error) { 21 return 22 } 23 func (this *testConn) Write(b []byte) (n int, err error) { 24 return 25 } 26 func (this *testConn) Close() error { 27 return nil 28 } 29 func (this *testConn) LocalAddr() net.Addr { 30 return &net.TCPAddr{ 31 IP: net.ParseIP(testutils.RandIP()), 32 Port: 1234, 33 } 34 } 35 func (this *testConn) RemoteAddr() net.Addr { 36 if this.addr != nil { 37 return this.addr 38 } 39 this.addr = &net.TCPAddr{ 40 IP: net.ParseIP(testutils.RandIP()), 41 Port: 1234, 42 } 43 return this.addr 44 } 45 func (this *testConn) SetDeadline(t time.Time) error { 46 return nil 47 } 48 func (this *testConn) SetReadDeadline(t time.Time) error { 49 return nil 50 } 51 func (this *testConn) SetWriteDeadline(t time.Time) error { 52 return nil 53 } 54 55 func BenchmarkMap_Add(b *testing.B) { 56 runtime.GOMAXPROCS(512) 57 58 var m = conns.NewMap() 59 60 b.RunParallel(func(pb *testing.PB) { 61 for pb.Next() { 62 var conn = &testConn{} 63 m.Add(conn) 64 m.Remove(conn) 65 } 66 }) 67 }