Open-Match 将 MMF 以独立部件拆出,其中一个好处是,可以让我们单独对配对逻辑进行单元测试。测试这个环节在想要进入营运前,也是大家不可避免的一个环节,今天会简单实验一下,针对官方 demo 所提供的 MMF,进行测试与 benchmark。
由於官方提供的 MMF 是由 golang 撰写的,今天将会以 golang 的测试工具进行测试,但如果各位打算以不同语言实作 MMF ,依然可以依照单元测试的原则,对你的 MMF 进行压测哦~
包含两个测试,ticketID 是否重复,以及两人成对的逻辑是否正确
使用 golang 执行单元测试
~ go test -v
=== RUN TestMakeMatchesDeduplicate
--- PASS: TestMakeMatchesDeduplicate (0.00s)
=== RUN TestMakeMatches
--- PASS: TestMakeMatches (0.00s)
PASS
ok github.com/WeiWeiWesley/open-match/examples/functions/golang/soloduel/mmf 0.015s
同样使用 mmf/soloduel,但加上笔者提供的 test code 执行效能测试。
test code
func BenchmarkMakeMatches(b *testing.B) {
for i := 0; i < b.N; i++ {
poolNameToTickets, ticketsCount := requestCreator()
equal := int(ticketsCount / 2) //期望总组数
matches, err := makeMatches(poolNameToTickets)
if err != nil {
b.Error(err)
}
if len(matches) != equal {
b.Errorf("should create total num of %d matches but got %d", equal, len(matches))
}
for _, match := range matches {
if len(match.Tickets) != 2 {
b.Error("match.Tickets count err")
}
if match.MatchFunction != matchName {
b.Error("matchName err")
}
}
}
}
//随机产生请求
func requestCreator() (map[string][]*pb.Ticket, int) {
poolNum := rand.Intn(9) + 1 // random numbers of pools 1~10
poolNameToTickets := map[string][]*pb.Ticket{}
ticketCount := 1
for i := 0; i < poolNum; i++ {
aPoolTicketNum := rand.Intn(99) + 1 // random numbers of tickets 1~100
poolName := fmt.Sprintf("pool%d", i)
for j := 0; j < aPoolTicketNum; j++ {
poolNameToTickets[poolName] = append(poolNameToTickets[poolName], &pb.Ticket{
Id: fmt.Sprintf("%d", ticketCount),
})
}
}
return poolNameToTickets, ticketCount - 1
}
使用 golang 执行效能测试
结果可以看出,mmf/soloduel 可以在每秒执行 25,842次,平均单次执行时间为 47,391 ns
~ go test -v -bench=. -run=none .
goos: darwin
goarch: amd64
pkg: github.com/WeiWeiWesley/open-match/examples/functions/golang/soloduel/mmf
cpu: Intel(R) Core(TM) i5-7267U CPU @ 3.10GHz
BenchmarkMakeMatches
BenchmarkMakeMatches-4 25842 47391 ns/op
PASS
ok github.com/WeiWeiWesley/open-match/examples/functions/golang/soloduel/mmf 1.727s
一、前言 大家不论学习什麽程序语言、选择走前端後端或系统分析,一定都学过HTML这个文本标记语言...
新零售行销模式案例,全通路时代来临该如何布局,一直以来都在担任辅导顾问为中小企业解决网路行销问题但都...
上一篇我们已将伊甸基金会的口罩脸孔资料集上传到 nilvana 的 Vision Studio 中,...
什麽是AutoML 根据 Microsoft的说法节录如下: 自动化机器学习 (亦称为自动化 ML ...
看完这篇文章你会得到的成果图 此篇文章的范例程序码 github https://github.co...