(b *testing.B)
| 253 | var tokenToPreventOptimization uint64 |
| 254 | |
| 255 | func BenchmarkSpanIDAndKindToToken(b *testing.B) { |
| 256 | type testDataSpanID struct { |
| 257 | SpanID []byte |
| 258 | Kind int |
| 259 | } |
| 260 | |
| 261 | randomTestCasesSpanID := func(n int, idLen int) []testDataSpanID { |
| 262 | testCases := make([]testDataSpanID, 0, n) |
| 263 | for i := 0; i < n; i++ { |
| 264 | id := make([]byte, idLen) |
| 265 | for j := range id { |
| 266 | id[j] = byte(rand.Intn(256)) |
| 267 | } |
| 268 | testCases = append(testCases, testDataSpanID{SpanID: id, Kind: rand.Intn(6)}) |
| 269 | } |
| 270 | return testCases |
| 271 | } |
| 272 | |
| 273 | benchmarks := []struct { |
| 274 | name string |
| 275 | data []testDataSpanID |
| 276 | }{ |
| 277 | { |
| 278 | name: "id length 4", |
| 279 | data: randomTestCasesSpanID(1_000, 4), |
| 280 | }, |
| 281 | { |
| 282 | name: "id length 8", |
| 283 | data: randomTestCasesSpanID(1_000, 8), |
| 284 | }, |
| 285 | } |
| 286 | for _, bc := range benchmarks { |
| 287 | b.Run(bc.name, func(b *testing.B) { |
| 288 | b.ResetTimer() |
| 289 | for i := 0; i < b.N; i++ { |
| 290 | d := bc.data[i%len(bc.data)] |
| 291 | tokenToPreventOptimization = SpanIDAndKindToToken(d.SpanID, d.Kind) |
| 292 | } |
| 293 | b.ReportAllocs() |
| 294 | }) |
| 295 | } |
| 296 | } |
| 297 | |
| 298 | func TestPadTraceIDString(t *testing.T) { |
| 299 | tc := []struct { |
nothing calls this directly
no test coverage detected