2
0
mirror of https://github.com/soheilhy/cmux.git synced 2024-11-10 11:41:52 +08:00

Parallelize benchmarks

This commit is contained in:
Tamir Duberstein 2016-07-12 12:13:54 -04:00
parent f952454ed9
commit f4d9321cb4
No known key found for this signature in database
GPG Key ID: 1C1E98CC8E17BB89
2 changed files with 30 additions and 23 deletions

View File

@ -24,4 +24,5 @@ before_script:
- if [[ $TRAVIS_GO_VERSION == 1.6* ]]; then go tool vet --shadow .; fi - if [[ $TRAVIS_GO_VERSION == 1.6* ]]; then go tool vet --shadow .; fi
script: script:
- go test -v ./... - go test -bench . -v ./...
- go test -race -bench . -v ./...

View File

@ -62,12 +62,14 @@ func BenchmarkCMuxConnHTTP1(b *testing.B) {
wg.Add(b.N) wg.Add(b.N)
b.ResetTimer() b.ResetTimer()
for i := 0; i < b.N; i++ { b.RunParallel(func(pb *testing.PB) {
c := &mockConn{ for pb.Next() {
wg.Add(1)
m.serve(&mockConn{
r: bytes.NewReader(benchHTTP1Payload), r: bytes.NewReader(benchHTTP1Payload),
}, donec, &wg)
} }
m.serve(c, donec, &wg) })
}
} }
func BenchmarkCMuxConnHTTP2(b *testing.B) { func BenchmarkCMuxConnHTTP2(b *testing.B) {
@ -80,12 +82,14 @@ func BenchmarkCMuxConnHTTP2(b *testing.B) {
wg.Add(b.N) wg.Add(b.N)
b.ResetTimer() b.ResetTimer()
for i := 0; i < b.N; i++ { b.RunParallel(func(pb *testing.PB) {
c := &mockConn{ for pb.Next() {
wg.Add(1)
m.serve(&mockConn{
r: bytes.NewReader(benchHTTP2Payload), r: bytes.NewReader(benchHTTP2Payload),
}, donec, &wg)
} }
m.serve(c, donec, &wg) })
}
} }
func BenchmarkCMuxConnHTTP1n2(b *testing.B) { func BenchmarkCMuxConnHTTP1n2(b *testing.B) {
@ -98,15 +102,16 @@ func BenchmarkCMuxConnHTTP1n2(b *testing.B) {
donec := make(chan struct{}) donec := make(chan struct{})
var wg sync.WaitGroup var wg sync.WaitGroup
wg.Add(b.N)
b.ResetTimer() b.ResetTimer()
for i := 0; i < b.N; i++ { b.RunParallel(func(pb *testing.PB) {
c := &mockConn{ for pb.Next() {
wg.Add(1)
m.serve(&mockConn{
r: bytes.NewReader(benchHTTP2Payload), r: bytes.NewReader(benchHTTP2Payload),
}, donec, &wg)
} }
m.serve(c, donec, &wg) })
}
} }
func BenchmarkCMuxConnHTTP2n1(b *testing.B) { func BenchmarkCMuxConnHTTP2n1(b *testing.B) {
@ -119,13 +124,14 @@ func BenchmarkCMuxConnHTTP2n1(b *testing.B) {
donec := make(chan struct{}) donec := make(chan struct{})
var wg sync.WaitGroup var wg sync.WaitGroup
wg.Add(b.N)
b.ResetTimer() b.ResetTimer()
for i := 0; i < b.N; i++ { b.RunParallel(func(pb *testing.PB) {
c := &mockConn{ for pb.Next() {
wg.Add(1)
m.serve(&mockConn{
r: bytes.NewReader(benchHTTP1Payload), r: bytes.NewReader(benchHTTP1Payload),
}, donec, &wg)
} }
m.serve(c, donec, &wg) })
}
} }