mirror of
https://github.com/golang/go
synced 2024-11-12 09:20:22 -07:00
net/http: add TLS benchmark
R=golang-codereviews, bradfitz CC=golang-codereviews https://golang.org/cl/110080045
This commit is contained in:
parent
03f2189a1b
commit
8c8bf3cc76
@ -2559,24 +2559,43 @@ func BenchmarkClientServer(b *testing.B) {
|
||||
}
|
||||
|
||||
func BenchmarkClientServerParallel4(b *testing.B) {
|
||||
benchmarkClientServerParallel(b, 4)
|
||||
benchmarkClientServerParallel(b, 4, false)
|
||||
}
|
||||
|
||||
func BenchmarkClientServerParallel64(b *testing.B) {
|
||||
benchmarkClientServerParallel(b, 64)
|
||||
benchmarkClientServerParallel(b, 64, false)
|
||||
}
|
||||
|
||||
func benchmarkClientServerParallel(b *testing.B, parallelism int) {
|
||||
func BenchmarkClientServerParallelTLS4(b *testing.B) {
|
||||
benchmarkClientServerParallel(b, 4, true)
|
||||
}
|
||||
|
||||
func BenchmarkClientServerParallelTLS64(b *testing.B) {
|
||||
benchmarkClientServerParallel(b, 64, true)
|
||||
}
|
||||
|
||||
func benchmarkClientServerParallel(b *testing.B, parallelism int, useTLS bool) {
|
||||
b.ReportAllocs()
|
||||
ts := httptest.NewServer(HandlerFunc(func(rw ResponseWriter, r *Request) {
|
||||
ts := httptest.NewUnstartedServer(HandlerFunc(func(rw ResponseWriter, r *Request) {
|
||||
fmt.Fprintf(rw, "Hello world.\n")
|
||||
}))
|
||||
if useTLS {
|
||||
ts.StartTLS()
|
||||
} else {
|
||||
ts.Start()
|
||||
}
|
||||
defer ts.Close()
|
||||
b.ResetTimer()
|
||||
b.SetParallelism(parallelism)
|
||||
b.RunParallel(func(pb *testing.PB) {
|
||||
noVerifyTransport := &Transport{
|
||||
TLSClientConfig: &tls.Config{
|
||||
InsecureSkipVerify: true,
|
||||
},
|
||||
}
|
||||
client := &Client{Transport: noVerifyTransport}
|
||||
for pb.Next() {
|
||||
res, err := Get(ts.URL)
|
||||
res, err := client.Get(ts.URL)
|
||||
if err != nil {
|
||||
b.Logf("Get: %v", err)
|
||||
continue
|
||||
|
Loading…
Reference in New Issue
Block a user