diff --git a/protocols/bgp/packet/large_community_benchmark_test.go b/protocols/bgp/packet/large_community_benchmark_test.go new file mode 100644 index 0000000000000000000000000000000000000000..7e37bcdf98de064442e4e10d343d31c45448ab74 --- /dev/null +++ b/protocols/bgp/packet/large_community_benchmark_test.go @@ -0,0 +1,28 @@ +package packet + +import ( + "fmt" + "strconv" + "strings" + "testing" +) + +func BenchmarkParseLargeCommunityString(b *testing.B) { + for _, i := range []int{1, 2, 4, 8, 16, 32} { + str := getNNumbers(i) + input := strings.Join([]string{str, str, str}, ",") + b.Run(fmt.Sprintf("BenchmarkParseLargeCommunityString-%d", i), func(b *testing.B) { + for n := 0; n < b.N; n++ { + ParseLargeCommunityString(input) + } + }) + } +} + +func getNNumbers(n int) (ret string) { + var numbers string + for i := 0; i < n; i++ { + numbers += strconv.Itoa(i % 10) + } + return numbers +}