MCPcopy
hub / github.com/grafana/tempo / BenchmarkSpanIDAndKindToToken

Function BenchmarkSpanIDAndKindToToken

pkg/util/traceid_test.go:255–296  ·  view source on GitHub ↗
(b *testing.B)

Source from the content-addressed store, hash-verified

253var tokenToPreventOptimization uint64
254
255func 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
298func TestPadTraceIDString(t *testing.T) {
299 tc := []struct {

Callers

nothing calls this directly

Calls 2

SpanIDAndKindToTokenFunction · 0.85
RunMethod · 0.45

Tested by

no test coverage detected