chore: add benchmark r/w
This commit is contained in:
parent
04e3c4f892
commit
6b13afb1ea
4 changed files with 29 additions and 11 deletions
|
@ -615,6 +615,10 @@ func benchmarkProxy(b *testing.B, proxy C.ProxyAdapter) {
|
||||||
require.NoError(b, err)
|
require.NoError(b, err)
|
||||||
defer l.Close()
|
defer l.Close()
|
||||||
|
|
||||||
|
chunkSize := int64(16 * 1024)
|
||||||
|
chunk := make([]byte, chunkSize)
|
||||||
|
rand.Read(chunk)
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
c, err := l.Accept()
|
c, err := l.Accept()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -622,12 +626,17 @@ func benchmarkProxy(b *testing.B, proxy C.ProxyAdapter) {
|
||||||
}
|
}
|
||||||
defer c.Close()
|
defer c.Close()
|
||||||
|
|
||||||
|
go func() {
|
||||||
|
for {
|
||||||
|
_, err := c.Write(chunk)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}()
|
||||||
io.Copy(io.Discard, c)
|
io.Copy(io.Discard, c)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
chunkSize := int64(16 * 1024)
|
|
||||||
chunk := make([]byte, chunkSize)
|
|
||||||
rand.Read(chunk)
|
|
||||||
conn, err := proxy.DialContext(context.Background(), &C.Metadata{
|
conn, err := proxy.DialContext(context.Background(), &C.Metadata{
|
||||||
Host: localIP.String(),
|
Host: localIP.String(),
|
||||||
DstPort: "10001",
|
DstPort: "10001",
|
||||||
|
@ -638,11 +647,20 @@ func benchmarkProxy(b *testing.B, proxy C.ProxyAdapter) {
|
||||||
_, err = conn.Write([]byte("skip protocol handshake"))
|
_, err = conn.Write([]byte("skip protocol handshake"))
|
||||||
require.NoError(b, err)
|
require.NoError(b, err)
|
||||||
|
|
||||||
|
b.Run("Write", func(b *testing.B) {
|
||||||
b.SetBytes(chunkSize)
|
b.SetBytes(chunkSize)
|
||||||
b.ResetTimer()
|
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
conn.Write(chunk)
|
conn.Write(chunk)
|
||||||
}
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
b.Run("Read", func(b *testing.B) {
|
||||||
|
b.SetBytes(chunkSize)
|
||||||
|
buf := make([]byte, chunkSize)
|
||||||
|
for i := 0; i < b.N; i++ {
|
||||||
|
conn.Read(buf)
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestClash_Basic(t *testing.T) {
|
func TestClash_Basic(t *testing.T) {
|
||||||
|
|
|
@ -150,7 +150,7 @@ func Benchmark_Snell(b *testing.B) {
|
||||||
Binds: []string{fmt.Sprintf("%s:/config.conf", C.Path.Resolve("snell-http.conf"))},
|
Binds: []string{fmt.Sprintf("%s:/config.conf", C.Path.Resolve("snell-http.conf"))},
|
||||||
}
|
}
|
||||||
|
|
||||||
id, err := startContainer(cfg, hostCfg, "snell-http")
|
id, err := startContainer(cfg, hostCfg, "snell-bench")
|
||||||
require.NoError(b, err)
|
require.NoError(b, err)
|
||||||
|
|
||||||
b.Cleanup(func() {
|
b.Cleanup(func() {
|
||||||
|
|
|
@ -167,7 +167,7 @@ func Benchmark_Shadowsocks(b *testing.B) {
|
||||||
PortBindings: defaultPortBindings,
|
PortBindings: defaultPortBindings,
|
||||||
}
|
}
|
||||||
|
|
||||||
id, err := startContainer(cfg, hostCfg, "ss")
|
id, err := startContainer(cfg, hostCfg, "ss-bench")
|
||||||
require.NoError(b, err)
|
require.NoError(b, err)
|
||||||
|
|
||||||
b.Cleanup(func() {
|
b.Cleanup(func() {
|
||||||
|
|
|
@ -371,7 +371,7 @@ func Benchmark_Vmess(b *testing.B) {
|
||||||
Binds: []string{fmt.Sprintf("%s:/etc/v2ray/config.json", configPath)},
|
Binds: []string{fmt.Sprintf("%s:/etc/v2ray/config.json", configPath)},
|
||||||
}
|
}
|
||||||
|
|
||||||
id, err := startContainer(cfg, hostCfg, "vmess-aead")
|
id, err := startContainer(cfg, hostCfg, "vmess-bench")
|
||||||
require.NoError(b, err)
|
require.NoError(b, err)
|
||||||
|
|
||||||
b.Cleanup(func() {
|
b.Cleanup(func() {
|
||||||
|
|
Loading…
Reference in a new issue