内容简介:func BenchmarkXxx(b *testing.B)go test -bench="."判定失败接口
格式:
func BenchmarkXxx(b *testing.B)
简单代码:
package examples
import (
"io/ioutil"
"net/http"
"testing"
)
// 测试并发效率
func BenchmarkLoopsParallel(b *testing.B) {
b.RunParallel(func(pb *testing.PB) { //并发
for pb.Next() {
resp, err := http.Get("http://10.10.200.128:8080/image?t=MDA")
if err != nil {
// handle error
}
cookies := resp.Cookies()
verify_key := ""
for _, v := range cookies {
if v.Name == "VERIFY_KEY" {
verify_key = v.Value
}
}
if err != nil {
// handle error
}
defer resp.Body.Close()
if verify_key == "" {
b.Fail()
}
}
})
}
运行
go test -bench="."
- -parallel 50 设置并发
- -count n 设置次数
testing.T
判定失败接口
- Fail 失败继续
- FailNow 失败终止
打印信息接口
- Log 数据流 (cout类似)
- Logf format (printf 类似)
- SkipNow 跳过当前测试
- Skiped 检测是否跳过
综合接口产生:
- Error / Errorf 报告出错继续 [ Log / Logf + Fail ]
- Fatel / Fatelf 报告出错终止 [ Log / Logf + FailNow ]
- Skip / Skipf 报告并跳过 [ Log / Logf + SkipNow ]
testing.B
首先 , testing.B 拥有testing.T 的全部接口。
- SetBytes( i uint64) 统计内存消耗, 如果你需要的话。
- SetParallelism(p int) 制定并行数目。
- StartTimer / StopTimer / ResertTimer 操作计时器
testing.PB
- Next() 接口 。 判断是否继续循环
注意点
- 文件需已test.go结尾
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
Java Message Service API Tutorial and Reference
Hapner, Mark; Burridge, Rich; Sharma, Rahul / 2002-2 / $ 56.49
Java Message Service (JMS) represents a powerful solution for communicating between Java enterprise applications, software components, and legacy systems. In this authoritative tutorial and comprehens......一起来看看 《Java Message Service API Tutorial and Reference》 这本书的介绍吧!
Markdown 在线编辑器
Markdown 在线编辑器
RGB HSV 转换
RGB HSV 互转工具