From b3a293ab078eb192001871be6fcb49e9749f20a7 Mon Sep 17 00:00:00 2001 From: Dreamacro <8615343+Dreamacro@users.noreply.github.com> Date: Thu, 22 Jul 2021 00:01:11 +0800 Subject: [PATCH] Chore: benchmark explanation --- test/README.md | 10 ++++++++++ test/clash_test.go | 5 +++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/test/README.md b/test/README.md index dec9999c..823fc544 100644 --- a/test/README.md +++ b/test/README.md @@ -47,3 +47,13 @@ Prerequisite ``` $ go test -p 1 -v ``` + +benchmark (Linux) + +> Cannot represent the throughput of the protocol on your machine +> but you can compare the corresponding throughput of the protocol on clash +> (change chunkSize to measure the maximum throughput of clash on your machine) + +``` +$ go test -benchmem -run=^$ -bench . +``` diff --git a/test/clash_test.go b/test/clash_test.go index 7d373bbd..366cc260 100644 --- a/test/clash_test.go +++ b/test/clash_test.go @@ -636,7 +636,8 @@ func benchmarkProxy(b *testing.B, proxy C.ProxyAdapter) { c.Close() }() - chunk := make([]byte, 1024) + chunkSize := int64(16 * 1024) + chunk := make([]byte, chunkSize) conn, err := proxy.DialContext(context.Background(), &C.Metadata{ Host: localIP.String(), DstPort: "10001", @@ -646,7 +647,7 @@ func benchmarkProxy(b *testing.B, proxy C.ProxyAdapter) { assert.FailNow(b, err.Error()) } - b.SetBytes(1024) + b.SetBytes(chunkSize) b.ResetTimer() for i := 0; i < b.N; i++ { if _, err := conn.Write(chunk); err != nil {