github.com/GFW-knocker/wireguard@v1.0.1/tun/checksum_test.go (about) 1 package tun 2 3 import ( 4 "fmt" 5 "math/rand" 6 "testing" 7 ) 8 9 func BenchmarkChecksum(b *testing.B) { 10 lengths := []int{ 11 64, 12 128, 13 256, 14 512, 15 1024, 16 1500, 17 2048, 18 4096, 19 8192, 20 9000, 21 9001, 22 } 23 24 for _, length := range lengths { 25 b.Run(fmt.Sprintf("%d", length), func(b *testing.B) { 26 buf := make([]byte, length) 27 rng := rand.New(rand.NewSource(1)) 28 rng.Read(buf) 29 b.ResetTimer() 30 for i := 0; i < b.N; i++ { 31 checksum(buf, 0) 32 } 33 }) 34 } 35 }