From 7a1c417b57db3845d333bbde34916bf42de607a9 Mon Sep 17 00:00:00 2001 From: GoEdgeLab Date: Mon, 15 Apr 2024 14:15:30 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=B5=8B=E8=AF=95=E7=94=A8?= =?UTF-8?q?=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/conns/map_test_test.go | 67 +++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 internal/conns/map_test_test.go diff --git a/internal/conns/map_test_test.go b/internal/conns/map_test_test.go new file mode 100644 index 0000000..03cda22 --- /dev/null +++ b/internal/conns/map_test_test.go @@ -0,0 +1,67 @@ +// Copyright 2024 GoEdge CDN goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cn . + +package conns_test + +import ( + "github.com/TeaOSLab/EdgeNode/internal/conns" + "github.com/TeaOSLab/EdgeNode/internal/utils/testutils" + "net" + "runtime" + "testing" + "time" +) + +type testConn struct { + net.Conn + + addr net.Addr +} + +func (this *testConn) Read(b []byte) (n int, err error) { + return +} +func (this *testConn) Write(b []byte) (n int, err error) { + return +} +func (this *testConn) Close() error { + return nil +} +func (this *testConn) LocalAddr() net.Addr { + return &net.TCPAddr{ + IP: net.ParseIP(testutils.RandIP()), + Port: 1234, + } +} +func (this *testConn) RemoteAddr() net.Addr { + if this.addr != nil { + return this.addr + } + this.addr = &net.TCPAddr{ + IP: net.ParseIP(testutils.RandIP()), + Port: 1234, + } + return this.addr +} +func (this *testConn) SetDeadline(t time.Time) error { + return nil +} +func (this *testConn) SetReadDeadline(t time.Time) error { + return nil +} +func (this *testConn) SetWriteDeadline(t time.Time) error { + return nil +} + +func BenchmarkMap_Add(b *testing.B) { + runtime.GOMAXPROCS(512) + + var m = conns.NewMap() + + b.RunParallel(func(pb *testing.PB) { + for pb.Next() { + var conn = &testConn{} + m.Add(conn) + m.Remove(conn) + } + }) +}