mirror of
https://github.com/xtaci/smux.git
synced 2024-04-21 10:51:48 +00:00
update test
This commit is contained in:
+16
-3
@@ -488,7 +488,6 @@ func BenchmarkConnSmux(b *testing.B) {
|
||||
bench(b, cs, ss)
|
||||
}
|
||||
|
||||
/*
|
||||
func BenchmarkConnTCP(b *testing.B) {
|
||||
cs, ss, err := getTCPConnectionPair()
|
||||
if err != nil {
|
||||
@@ -498,7 +497,6 @@ func BenchmarkConnTCP(b *testing.B) {
|
||||
defer ss.Close()
|
||||
bench(b, cs, ss)
|
||||
}
|
||||
*/
|
||||
|
||||
func getSmuxStreamPair() (*Stream, *Stream, error) {
|
||||
c1, c2, err := getTCPConnectionPair()
|
||||
@@ -562,10 +560,25 @@ func getTCPConnectionPair() (net.Conn, net.Conn, error) {
|
||||
|
||||
func bench(b *testing.B, rd io.Reader, wr io.Writer) {
|
||||
buf := make([]byte, 128*1024)
|
||||
buf2 := make([]byte, 128*1024)
|
||||
b.SetBytes(128 * 1024)
|
||||
b.ResetTimer()
|
||||
|
||||
var wg sync.WaitGroup
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
count := 0
|
||||
for {
|
||||
n, _ := rd.Read(buf2)
|
||||
count += n
|
||||
if count == 128*1024*b.N {
|
||||
return
|
||||
}
|
||||
}
|
||||
}()
|
||||
for i := 0; i < b.N; i++ {
|
||||
wr.Write(buf)
|
||||
rd.Read(buf)
|
||||
}
|
||||
wg.Wait()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user