Add unordered benchmark for RecvDataFromRemote

This commit is contained in:
Andy Wang 2020-12-27 21:40:59 +00:00
parent 57bb437802
commit e0b97db7cc
No known key found for this signature in database
GPG Key ID: 181B49F9F38F3374
1 changed files with 25 additions and 16 deletions

View File

@ -4,6 +4,7 @@ import (
"bytes" "bytes"
"github.com/cbeuw/connutil" "github.com/cbeuw/connutil"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"io/ioutil"
"math/rand" "math/rand"
"strconv" "strconv"
"sync" "sync"
@ -415,7 +416,7 @@ func TestSession_timeoutAfter(t *testing.T) {
} }
} }
func BenchmarkRecvDataFromRemote_Ordered(b *testing.B) { func BenchmarkRecvDataFromRemote(b *testing.B) {
testPayload := make([]byte, testPayloadLen) testPayload := make([]byte, testPayloadLen)
rand.Read(testPayload) rand.Read(testPayload)
f := &Frame{ f := &Frame{
@ -439,23 +440,31 @@ func BenchmarkRecvDataFromRemote_Ordered(b *testing.B) {
for name, ep := range table { for name, ep := range table {
ep := ep ep := ep
b.Run(name, func(b *testing.B) { b.Run(name, func(b *testing.B) {
seshConfig := seshConfigs["ordered"] for seshType, seshConfig := range seshConfigs {
obfuscator, _ := MakeObfuscator(ep, sessionKey) b.Run(seshType, func(b *testing.B) {
seshConfig.Obfuscator = obfuscator obfuscator, _ := MakeObfuscator(ep, sessionKey)
sesh := MakeSession(0, seshConfig) seshConfig.Obfuscator = obfuscator
sesh := MakeSession(0, seshConfig)
binaryFrames := [maxIter][]byte{} go func() {
for i := 0; i < maxIter; i++ { stream, _ := sesh.Accept()
obfsBuf := make([]byte, obfsBufLen) stream.(*Stream).WriteTo(ioutil.Discard)
n, _ := sesh.obfuscate(f, obfsBuf, 0) }()
binaryFrames[i] = obfsBuf[:n]
f.Seq++
}
b.SetBytes(int64(len(f.Payload))) binaryFrames := [maxIter][]byte{}
b.ResetTimer() for i := 0; i < maxIter; i++ {
for i := 0; i < b.N; i++ { obfsBuf := make([]byte, obfsBufLen)
sesh.recvDataFromRemote(binaryFrames[i]) n, _ := sesh.obfuscate(f, obfsBuf, 0)
binaryFrames[i] = obfsBuf[:n]
f.Seq++
}
b.SetBytes(int64(len(f.Payload)))
b.ResetTimer()
for i := 0; i < b.N; i++ {
sesh.recvDataFromRemote(binaryFrames[i])
}
})
} }
}) })
} }