提交message项目;增加基准测试

This commit is contained in:
joylink_zhangsai 2023-07-28 14:22:54 +08:00
parent 617b0b66b8
commit a28abc6bb2
3 changed files with 182 additions and 0 deletions

1
bj-rtss-message Submodule

@ -0,0 +1 @@
Subproject commit c09c46511d43178e55491efeab848445ea35ddbf

View File

@ -1,8 +1,14 @@
package dynamics
import (
"encoding/hex"
"github.com/panjf2000/gnet/v2"
"io"
"joylink.club/bj-rtsts-server/config"
"net"
"runtime"
"testing"
"time"
)
func TestRunUdpServer(t *testing.T) {
@ -19,3 +25,173 @@ func TestSendTurnoutInfo(t *testing.T) {
RPosition: false,
})
}
func BenchmarkUdpServer_OnTraffic(b *testing.B) {
runtime.GOMAXPROCS(1) //1个协程
buf, _ := hex.DecodeString("0009012EE009000000070380000006000100020003000A000A000A000A000A000A000A")
// 创建 udpServer 对象
server := &udpServer{}
// 创建虚拟的 gnet.Conn 对象
conn := &virtualConn{
readBuffer: buf,
}
// 在 Benchmark 中运行测试
for i := 0; i < b.N; i++ {
server.OnTraffic(conn)
}
}
type virtualConn struct {
readBuffer []byte
}
func (vc *virtualConn) Read(p []byte) (n int, err error) {
//TODO implement me
panic("implement me")
}
func (vc *virtualConn) Write(p []byte) (n int, err error) {
//TODO implement me
panic("implement me")
}
func (vc *virtualConn) Context() (ctx interface{}) {
//TODO implement me
panic("implement me")
}
func (vc *virtualConn) SetContext(ctx interface{}) {
//TODO implement me
panic("implement me")
}
func (vc *virtualConn) Close() (err error) {
//TODO implement me
panic("implement me")
}
func (vc *virtualConn) WriteTo(w io.Writer) (n int64, err error) {
//TODO implement me
panic("implement me")
}
func (vc *virtualConn) Next(n int) (buf []byte, err error) {
//TODO implement me
return vc.readBuffer, nil
}
func (vc *virtualConn) Peek(n int) (buf []byte, err error) {
//TODO implement me
panic("implement me")
}
func (vc *virtualConn) Discard(n int) (discarded int, err error) {
//TODO implement me
panic("implement me")
}
func (vc *virtualConn) InboundBuffered() (n int) {
//TODO implement me
panic("implement me")
}
func (vc *virtualConn) ReadFrom(r io.Reader) (n int64, err error) {
//TODO implement me
panic("implement me")
}
func (vc *virtualConn) Writev(bs [][]byte) (n int, err error) {
//TODO implement me
panic("implement me")
}
func (vc *virtualConn) Flush() (err error) {
//TODO implement me
panic("implement me")
}
func (vc *virtualConn) OutboundBuffered() (n int) {
//TODO implement me
panic("implement me")
}
func (vc *virtualConn) AsyncWrite(buf []byte, callback gnet.AsyncCallback) (err error) {
//TODO implement me
panic("implement me")
}
func (vc *virtualConn) AsyncWritev(bs [][]byte, callback gnet.AsyncCallback) (err error) {
//TODO implement me
panic("implement me")
}
func (vc *virtualConn) Fd() int {
//TODO implement me
panic("implement me")
}
func (vc *virtualConn) Dup() (int, error) {
//TODO implement me
panic("implement me")
}
func (vc *virtualConn) SetReadBuffer(bytes int) error {
//TODO implement me
panic("implement me")
}
func (vc *virtualConn) SetWriteBuffer(bytes int) error {
//TODO implement me
panic("implement me")
}
func (vc *virtualConn) SetLinger(sec int) error {
//TODO implement me
panic("implement me")
}
func (vc *virtualConn) SetKeepAlivePeriod(d time.Duration) error {
//TODO implement me
panic("implement me")
}
func (vc *virtualConn) SetNoDelay(noDelay bool) error {
//TODO implement me
panic("implement me")
}
func (vc *virtualConn) LocalAddr() (addr net.Addr) {
//TODO implement me
panic("implement me")
}
func (vc *virtualConn) RemoteAddr() (addr net.Addr) {
//TODO implement me
panic("implement me")
}
func (vc *virtualConn) Wake(callback gnet.AsyncCallback) (err error) {
//TODO implement me
panic("implement me")
}
func (vc *virtualConn) CloseWithCallback(callback gnet.AsyncCallback) (err error) {
//TODO implement me
panic("implement me")
}
func (vc *virtualConn) SetDeadline(t time.Time) (err error) {
//TODO implement me
panic("implement me")
}
func (vc *virtualConn) SetReadDeadline(t time.Time) (err error) {
//TODO implement me
panic("implement me")
}
func (vc *virtualConn) SetWriteDeadline(t time.Time) (err error) {
//TODO implement me
panic("implement me")
}

View File

@ -0,0 +1,5 @@
package main
func main() {
}