github.com/MerlinKodo/sing-tun@v0.1.15/internal/clashtcpip/tcpip_arm64_test.go (about) 1 package clashtcpip 2 3 import ( 4 "crypto/rand" 5 "testing" 6 7 "golang.org/x/sys/cpu" 8 ) 9 10 func Test_SumNeon(t *testing.T) { 11 if !cpu.ARM64.HasASIMD { 12 t.Skipf("Neon unavailable") 13 } 14 15 bytes := make([]byte, chunkSize) 16 17 for size := 0; size <= chunkSize; size++ { 18 for count := 0; count < chunkCount; count++ { 19 _, err := rand.Reader.Read(bytes[:size]) 20 if err != nil { 21 t.Skipf("Rand read failed: %v", err) 22 } 23 24 compat := SumCompat(bytes[:size]) 25 neon := SumNeon(bytes[:size]) 26 27 if compat != neon { 28 t.Errorf("Sum of length=%d mismatched", size) 29 } 30 } 31 } 32 } 33 34 func Benchmark_SumNeon(b *testing.B) { 35 if !cpu.ARM64.HasASIMD { 36 b.Skipf("Neon unavailable") 37 } 38 39 bytes := make([]byte, chunkSize) 40 41 _, err := rand.Reader.Read(bytes) 42 if err != nil { 43 b.Skipf("Rand read failed: %v", err) 44 } 45 46 b.ResetTimer() 47 48 for i := 0; i < b.N; i++ { 49 SumNeon(bytes) 50 } 51 }