1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2025-10-13 20:44:04 -04:00

allocate buffer on stack

This commit is contained in:
Darien Raymond
2018-11-15 21:32:27 +01:00
parent a5ed9e00ab
commit a20262ef20
5 changed files with 27 additions and 4 deletions

View File

@@ -4,6 +4,7 @@ import (
"bytes"
"testing"
"v2ray.com/core/common"
"v2ray.com/core/common/buf"
"v2ray.com/core/common/net"
_ "v2ray.com/core/common/net/testing"
@@ -107,3 +108,17 @@ func TestReadUntilNull(t *testing.T) {
}
}
}
func BenchmarkReadUsernamePassword(b *testing.B) {
input := []byte{0x05, 0x01, 'a', 0x02, 'b', 'c'}
buffer := buf.New()
buffer.Write(input)
b.ResetTimer()
for i := 0; i < b.N; i++ {
_, _, err := ReadUsernamePassword(buffer)
common.Must(err)
buffer.Clear()
buffer.Extend(int32(len(input)))
}
}