Skip to content

Commit 4a4fe33

Browse files
committed
add sliceofstruct workload benchmark
1 parent 14f5b21 commit 4a4fe33

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

decoder_test.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2527,3 +2527,42 @@ func TestDecoder_SetMaxSize(t *testing.T) {
25272527
}
25282528
})
25292529
}
2530+
2531+
type keyvalue struct {
2532+
Key string
2533+
Value string
2534+
}
2535+
2536+
type sliceOfStructInput struct {
2537+
Attributes []keyvalue
2538+
Tags []keyvalue
2539+
}
2540+
2541+
func BenchmarkSliceOfStruct(b *testing.B) {
2542+
d := NewDecoder()
2543+
v := map[string][]string{
2544+
"Attributes.0.Key": {"foo0"},
2545+
"Attributes.0.Value": {"bar0"},
2546+
"Attributes.1.Key": {"foo1"},
2547+
"Attributes.1.Value": {"bar1"},
2548+
"Attributes.2.Key": {"foo2"},
2549+
"Attributes.2.Value": {"bar2"},
2550+
"Attributes.3.Key": {"foo3"},
2551+
"Attributes.3.Value": {"bar3"},
2552+
"Attributes.4.Key": {"foo4"},
2553+
"Attributes.4.Value": {"bar4"},
2554+
"Attributes.5.Key": {"foo5"},
2555+
"Attributes.5.Value": {"bar5"},
2556+
"Tags.0.Key": {"baz0"},
2557+
"Tags.0.Value": {"bam0"},
2558+
"Tags.1.Key": {"baz1"},
2559+
"Tags.1.Value": {"bam1"},
2560+
"Tags.2.Key": {"baz2"},
2561+
"Tags.2.Value": {"bam2"},
2562+
}
2563+
b.ResetTimer()
2564+
for i := 0; i < b.N; i++ {
2565+
in := &sliceOfStructInput{}
2566+
_ = d.Decode(in, v)
2567+
}
2568+
}

0 commit comments

Comments
 (0)