@@ -31,7 +31,11 @@ func BenchmarkBuildWithNoCustomAttrs(b *testing.B) {
3131}
3232
3333func BenchmarkBuildWithCustomAttributes (b * testing.B ) {
34- for _ , n := range []int {sharedtest .SmallNumberOfCustomAttributes , sharedtest .LargeNumberOfCustomAttributes } {
34+ for _ , n := range []int {
35+ sharedtest .SmallNumberOfCustomAttributes ,
36+ sharedtest .MiddleNumberOfCustomAttributes ,
37+ sharedtest .LargeNumberOfCustomAttributes ,
38+ } {
3539 b .Run (fmt .Sprintf ("with %d attributes" , n ), func (b * testing.B ) {
3640 attrs := sharedtest .MakeCustomAttributeNamesAndValues (n )
3741 b .ResetTimer ()
@@ -46,6 +50,26 @@ func BenchmarkBuildWithCustomAttributes(b *testing.B) {
4650 }
4751}
4852
53+ func BenchmarkBuildWithCustomAttributesWithCapacity (b * testing.B ) {
54+ for _ , n := range []int {
55+ sharedtest .SmallNumberOfCustomAttributes ,
56+ sharedtest .MiddleNumberOfCustomAttributes ,
57+ sharedtest .LargeNumberOfCustomAttributes ,
58+ } {
59+ b .Run (fmt .Sprintf ("with %d attributes" , n ), func (b * testing.B ) {
60+ attrs := sharedtest .MakeCustomAttributeNamesAndValues (n )
61+ b .ResetTimer ()
62+ for i := 0 ; i < b .N ; i ++ {
63+ builder := NewBuilderWithCapacity ("key" , n )
64+ for _ , a := range attrs {
65+ builder .SetValue (a .Name , a .Value )
66+ }
67+ benchmarkContext = builder .Build ()
68+ }
69+ })
70+ }
71+ }
72+
4973func BenchmarkBuildWithPrivate (b * testing.B ) {
5074 for i := 0 ; i < b .N ; i ++ {
5175 benchmarkContext = NewBuilder ("key" ).Name ("name" ).Private ("name" ).Build ()
0 commit comments