61 lines
1.3 KiB
Go
61 lines
1.3 KiB
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"runtime"
|
|
"server/game"
|
|
"server/game/mod/msg"
|
|
"testing"
|
|
)
|
|
|
|
// func TestBenchInit(t *testing.T) {
|
|
// f := "wmz00%d"
|
|
// for i := 0; i < 10000; i++ {
|
|
// UserName := fmt.Sprintf(f, i)
|
|
// game.G_GameLogicPtr.Db_AccountInfo.UserName = UserName
|
|
// game.G_GameLogicPtr.Db_AccountInfo.UserPassword = "123456"
|
|
// if game.G_GameLogicPtr.NewAccountInsertDataToDB() {
|
|
// fmt.Printf("UserName:%s\n init success", UserName)
|
|
// }
|
|
// }
|
|
// }
|
|
|
|
/*
|
|
*
|
|
cluster 消息处理基准测试
|
|
|
|
36716 34961 ns/op 1690 B/op 38 allocs/op
|
|
*/
|
|
func BenchmarkClusterMsg(b *testing.B) {
|
|
game.ClusterMgrInit()
|
|
runtime.GOMAXPROCS(8)
|
|
game.G_getGameLogic()
|
|
for i := 0; i < b.N; i++ {
|
|
m := &msg.Msg{
|
|
HandleType: msg.HANDLE_MOD_PLAYER_LOGIN,
|
|
Extra: 0,
|
|
}
|
|
game.MessageHandle(m)
|
|
}
|
|
}
|
|
|
|
func printMemUsage() {
|
|
var m runtime.MemStats
|
|
runtime.ReadMemStats(&m)
|
|
// 输出内存使用情况
|
|
fmt.Printf("Alloc = %v MiB", bToMb(m.Alloc))
|
|
fmt.Printf("\tTotalAlloc = %v MiB", bToMb(m.TotalAlloc))
|
|
fmt.Printf("\tSys = %v MiB", bToMb(m.Sys))
|
|
fmt.Printf("\tNumGC = %v\n", m.NumGC)
|
|
var playerCount int
|
|
game.G_GameLogicPtr.M_Players.Range(func(key, value interface{}) bool {
|
|
playerCount++
|
|
return true
|
|
})
|
|
fmt.Printf("\tPlayerNum = %v\n", playerCount)
|
|
}
|
|
|
|
func bToMb(b uint64) uint64 {
|
|
return b / 1024 / 1024
|
|
}
|