2
0
mirror of https://github.com/soheilhy/cmux.git synced 2024-11-13 04:56:33 +08:00
cmux/bench_test.go
Tamir Duberstein ff7a91405b Closing the root listener closes child listeners
Partially reverts b90740dfa9b286c06f58fa798929e2d2cb1299e5; the same
protection is now afforded by an RWMutex which protects the channels
while they are being served on.
2015-12-11 15:25:29 -05:00

46 lines
633 B
Go

package cmux
import (
"bytes"
"io"
"net"
"sync"
"testing"
)
type mockConn struct {
net.Conn
r io.Reader
}
func (c *mockConn) Read(b []byte) (n int, err error) {
return c.r.Read(b)
}
func BenchmarkCMuxConn(b *testing.B) {
benchHTTPPayload := make([]byte, 4096)
copy(benchHTTPPayload, []byte("GET http://www.w3.org/ HTTP/1.1"))
m := New(nil).(*cMux)
l := m.Match(HTTP1Fast())
go func() {
for {
if _, err := l.Accept(); err != nil {
return
}
}
}()
var mu sync.RWMutex
b.ResetTimer()
for i := 0; i < b.N; i++ {
c := &mockConn{
r: bytes.NewReader(benchHTTPPayload),
}
m.serve(c, &mu)
}
}