aboutsummaryrefslogtreecommitdiff
path: root/tun/checksum_test.go
blob: c1ccff531d062a7342bca90edb80ff38bbc6d83a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package tun

import (
	"fmt"
	"math/rand"
	"testing"
)

func BenchmarkChecksum(b *testing.B) {
	lengths := []int{
		64,
		128,
		256,
		512,
		1024,
		1500,
		2048,
		4096,
		8192,
		9000,
		9001,
	}

	for _, length := range lengths {
		b.Run(fmt.Sprintf("%d", length), func(b *testing.B) {
			buf := make([]byte, length)
			rng := rand.New(rand.NewSource(1))
			rng.Read(buf)
			b.ResetTimer()
			for i := 0; i < b.N; i++ {
				checksum(buf, 0)
			}
		})
	}
}