Commit 8c8bf3cc authored by Dmitriy Vyukov's avatar Dmitriy Vyukov

net/http: add TLS benchmark

R=golang-codereviews, bradfitz
CC=golang-codereviews
https://golang.org/cl/110080045
parent 03f2189a
...@@ -2559,24 +2559,43 @@ func BenchmarkClientServer(b *testing.B) { ...@@ -2559,24 +2559,43 @@ func BenchmarkClientServer(b *testing.B) {
} }
func BenchmarkClientServerParallel4(b *testing.B) { func BenchmarkClientServerParallel4(b *testing.B) {
benchmarkClientServerParallel(b, 4) benchmarkClientServerParallel(b, 4, false)
} }
func BenchmarkClientServerParallel64(b *testing.B) { 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() 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") fmt.Fprintf(rw, "Hello world.\n")
})) }))
if useTLS {
ts.StartTLS()
} else {
ts.Start()
}
defer ts.Close() defer ts.Close()
b.ResetTimer() b.ResetTimer()
b.SetParallelism(parallelism) b.SetParallelism(parallelism)
b.RunParallel(func(pb *testing.PB) { b.RunParallel(func(pb *testing.PB) {
noVerifyTransport := &Transport{
TLSClientConfig: &tls.Config{
InsecureSkipVerify: true,
},
}
client := &Client{Transport: noVerifyTransport}
for pb.Next() { for pb.Next() {
res, err := Get(ts.URL) res, err := client.Get(ts.URL)
if err != nil { if err != nil {
b.Logf("Get: %v", err) b.Logf("Get: %v", err)
continue continue
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment