File: tracestate_benchkmark_test.go

package info (click to toggle)
golang-opentelemetry-otel 1.31.0-5
  • links: PTS, VCS
  • area: main
  • in suites: experimental, forky, sid
  • size: 11,844 kB
  • sloc: makefile: 237; sh: 51
file content (47 lines) | stat: -rw-r--r-- 914 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

package trace

import (
	"testing"
)

func BenchmarkTraceStateParse(b *testing.B) {
	for _, test := range testcases {
		b.Run(test.name, func(b *testing.B) {
			b.ResetTimer()
			b.ReportAllocs()
			for i := 0; i < b.N; i++ {
				_, _ = ParseTraceState(test.in)
			}
		})
	}
}

func BenchmarkTraceStateString(b *testing.B) {
	for _, test := range testcases {
		if len(test.tracestate.list) == 0 {
			continue
		}
		b.Run(test.name, func(b *testing.B) {
			b.ResetTimer()
			b.ReportAllocs()
			for i := 0; i < b.N; i++ {
				_ = test.tracestate.String()
			}
		})
	}
}

func BenchmarkTraceStateInsert(b *testing.B) {
	for _, test := range insertTestcase {
		b.Run(test.name, func(b *testing.B) {
			b.ResetTimer()
			b.ReportAllocs()
			for i := 0; i < b.N; i++ {
				_, _ = test.tracestate.Insert(test.key, test.value)
			}
		})
	}
}