Golang Performance Test

Source: Internet
Author: User

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.

    1. File must have Test.go end

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.