inlet/flow: more elegant way to build titles for protobuf bench

This commit is contained in:
Vincent Bernat
2023-02-05 12:33:10 +01:00
parent 8f93f3abda
commit f07e2070b8

View File

@@ -42,10 +42,10 @@ func BenchmarkDecodeEncodeNetflow(b *testing.B) {
data = helpers.ReadPcapPayload(b, filepath.Join("decoder", "netflow", "testdata", "data-260.pcap")) data = helpers.ReadPcapPayload(b, filepath.Join("decoder", "netflow", "testdata", "data-260.pcap"))
for _, withEncoding := range []bool{true, false} { for _, withEncoding := range []bool{true, false} {
title := "with encoding" title := map[bool]string{
if !withEncoding { true: "with encoding",
title = "without encoding" false: "without encoding",
} }[withEncoding]
b.Run(title, func(b *testing.B) { b.Run(title, func(b *testing.B) {
for i := 0; i < b.N; i++ { for i := 0; i < b.N; i++ {
got = nfdecoder.Decode(decoder.RawFlow{Payload: data, Source: net.ParseIP("127.0.0.1")}) got = nfdecoder.Decode(decoder.RawFlow{Payload: data, Source: net.ParseIP("127.0.0.1")})
@@ -70,10 +70,10 @@ func BenchmarkDecodeEncodeSflow(b *testing.B) {
data := helpers.ReadPcapPayload(b, filepath.Join("decoder", "sflow", "testdata", "data-1140.pcap")) data := helpers.ReadPcapPayload(b, filepath.Join("decoder", "sflow", "testdata", "data-1140.pcap"))
for _, withEncoding := range []bool{true, false} { for _, withEncoding := range []bool{true, false} {
title := "with encoding" title := map[bool]string{
if !withEncoding { true: "with encoding",
title = "without encoding" false: "without encoding",
} }[withEncoding]
var got []*schema.FlowMessage var got []*schema.FlowMessage
b.Run(title, func(b *testing.B) { b.Run(title, func(b *testing.B) {
for i := 0; i < b.N; i++ { for i := 0; i < b.N; i++ {