Skip to content

Commit

Permalink
update test
Browse files Browse the repository at this point in the history
  • Loading branch information
xtaci committed Sep 8, 2016
1 parent f75ca5b commit c2aeb5b
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions session_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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()
Expand Down Expand Up @@ -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()
}

0 comments on commit c2aeb5b

Please sign in to comment.