当测试从API调用的数据库过程时,当它按顺序运行时,似乎在约3秒内始终保持一致。但是我们注意到,当同时有多个请求时,这可能需要更长时间,导致超时。我正在尝试将“同时发出多个请求”的情况作为
我尝试了
我的基准测试函数有问题吗?
否则我怎么能达到我想要的目标?
go test
进行复现。我尝试了
-parallel 10
go test标志,但时间仍然相同,约为28秒。我的基准测试函数有问题吗?
func Benchmark_RealCreate(b *testing.B) {
b.ResetTimer()
for n := 0; n < b.N; n++ {
name := randomdata.SillyName()
r := gofight.New()
u := []unit{unit{MefeUnitID: name, MefeCreatorUserID: "user", BzfeCreatorUserID: 55, ClassificationID: 2, UnitName: name, UnitDescriptionDetails: "Up on the hills and testing"}}
uJSON, _ := json.Marshal(u)
r.POST("/create").
SetBody(string(uJSON)).
Run(h.BasicEngine(), func(r gofight.HTTPResponse, rq gofight.HTTPRequest) {
assert.Contains(b, r.Body.String(), name)
assert.Equal(b, http.StatusOK, r.Code)
})
}
}
否则我怎么能达到我想要的目标?