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:
@@ -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)))
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user