Format:
Func benchmarkxxx (b *testing. B
Simple code:
package examplesimport ( "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() } } })}
Run
Go test-bench= "."
- -parallel 50 Setting concurrency
- -count n Set Number of times
Testing. T
Failed to determine interface
- Fail to continue
- Failnow failed to terminate
Print Information interface
- Log data stream (cout similar)
- LOGF format (printf similar)
- Skipnow Skip Current Test
- Skiped detect if skipping
Integrated Interface Generation:
- Error/errorf report Error continue [Log/logf + Fail]
- Fatel/fatelf report Error terminated [Log/logf + Failnow]
- SKIP/SKIPF report and Skip [Log/logf + Skipnow]
Testing. B
First, testing. B owns testing. All interfaces of T.
- SetBytes (I UInt64) statistics memory consumption, if you need to.
- Setparallelism (p int) to develop a parallel number.
- Starttimer/stoptimer/reserttimer Operation Timer
Testing. PB
- Next () interface. Determine if the loop continues
Watch out.
- File must have Test.go end