mirror of
https://github.com/golang/go
synced 2024-10-04 12:21:26 -06:00
net/http: use RunParallel in benchmarks
LGTM=bradfitz R=golang-codereviews, bradfitz CC=golang-codereviews https://golang.org/cl/68070043
This commit is contained in:
parent
b5705ed9ab
commit
96d5229818
@ -26,7 +26,6 @@ import (
|
|||||||
"runtime"
|
"runtime"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
"syscall"
|
"syscall"
|
||||||
"testing"
|
"testing"
|
||||||
@ -2280,22 +2279,16 @@ func BenchmarkClientServerParallel64(b *testing.B) {
|
|||||||
benchmarkClientServerParallel(b, 64)
|
benchmarkClientServerParallel(b, 64)
|
||||||
}
|
}
|
||||||
|
|
||||||
func benchmarkClientServerParallel(b *testing.B, conc int) {
|
func benchmarkClientServerParallel(b *testing.B, parallelism int) {
|
||||||
b.ReportAllocs()
|
b.ReportAllocs()
|
||||||
b.StopTimer()
|
|
||||||
ts := httptest.NewServer(HandlerFunc(func(rw ResponseWriter, r *Request) {
|
ts := httptest.NewServer(HandlerFunc(func(rw ResponseWriter, r *Request) {
|
||||||
fmt.Fprintf(rw, "Hello world.\n")
|
fmt.Fprintf(rw, "Hello world.\n")
|
||||||
}))
|
}))
|
||||||
defer ts.Close()
|
defer ts.Close()
|
||||||
b.StartTimer()
|
b.ResetTimer()
|
||||||
|
b.SetParallelism(parallelism)
|
||||||
numProcs := runtime.GOMAXPROCS(-1) * conc
|
b.RunParallel(func(pb *testing.PB) {
|
||||||
var wg sync.WaitGroup
|
for pb.Next() {
|
||||||
wg.Add(numProcs)
|
|
||||||
n := int32(b.N)
|
|
||||||
for p := 0; p < numProcs; p++ {
|
|
||||||
go func() {
|
|
||||||
for atomic.AddInt32(&n, -1) >= 0 {
|
|
||||||
res, err := Get(ts.URL)
|
res, err := Get(ts.URL)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
b.Logf("Get: %v", err)
|
b.Logf("Get: %v", err)
|
||||||
@ -2312,10 +2305,7 @@ func benchmarkClientServerParallel(b *testing.B, conc int) {
|
|||||||
panic("Got body: " + body)
|
panic("Got body: " + body)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
wg.Done()
|
})
|
||||||
}()
|
|
||||||
}
|
|
||||||
wg.Wait()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// A benchmark for profiling the server without the HTTP client code.
|
// A benchmark for profiling the server without the HTTP client code.
|
||||||
|
Loading…
Reference in New Issue
Block a user