| 1 |
// Copyright The OpenTelemetry Authors |
| 2 |
// SPDX-License-Identifier: Apache-2.0 |
| 3 |
|
| 4 |
package trace |
| 5 |
|
| 6 |
import ( |
| 7 |
"testing" |
| 8 |
) |
| 9 |
|
| 10 |
func BenchmarkTraceStateParse(b *testing.B) { |
| 11 |
for _, test := range testcases { |
| 12 |
b.Run(test.name, func(b *testing.B) { |
| 13 |
b.ResetTimer() |
| 14 |
b.ReportAllocs() |
| 15 |
for i := 0; i < b.N; i++ { |
| 16 |
_, _ = ParseTraceState(test.in) |
| 17 |
} |
| 18 |
}) |
| 19 |
} |
| 20 |
} |
| 21 |
|
| 22 |
func BenchmarkTraceStateString(b *testing.B) { |
| 23 |
for _, test := range testcases { |
| 24 |
if len(test.tracestate.list) == 0 { |
| 25 |
continue |
| 26 |
} |
| 27 |
b.Run(test.name, func(b *testing.B) { |
| 28 |
b.ResetTimer() |
| 29 |
b.ReportAllocs() |
| 30 |
for i := 0; i < b.N; i++ { |
| 31 |
_ = test.tracestate.String() |
| 32 |
} |
| 33 |
}) |
| 34 |
} |
| 35 |
} |
| 36 |
|
| 37 |
func BenchmarkTraceStateInsert(b *testing.B) { |
| 38 |
for _, test := range insertTestcase { |
| 39 |
b.Run(test.name, func(b *testing.B) { |
| 40 |
b.ResetTimer() |
| 41 |
b.ReportAllocs() |
| 42 |
for i := 0; i < b.N; i++ { |
| 43 |
_, _ = test.tracestate.Insert(test.key, test.value) |
| 44 |
} |
| 45 |
}) |
| 46 |
} |
| 47 |
} |