1// Copyright The OpenTelemetry Authors
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package label_test
16
17import (
18	"testing"
19
20	"go.opentelemetry.io/otel/label"
21)
22
23type test struct{}
24
25var (
26	arrayVal    = []string{"one", "two"}
27	arrayKeyVal = label.Array("array", arrayVal)
28
29	boolVal    = true
30	boolKeyVal = label.Bool("bool", boolVal)
31
32	intVal    = int(1)
33	intKeyVal = label.Int("int", intVal)
34
35	int8Val    = int8(1)
36	int8KeyVal = label.Int("int8", int(int8Val))
37
38	int16Val    = int16(1)
39	int16KeyVal = label.Int("int16", int(int16Val))
40
41	int32Val    = int32(1)
42	int32KeyVal = label.Int32("int32", int32Val)
43
44	int64Val    = int64(1)
45	int64KeyVal = label.Int64("int64", int64Val)
46
47	uintVal    = uint(1)
48	uintKeyVal = label.Uint("uint", uintVal)
49
50	uint8Val    = uint8(1)
51	uint8KeyVal = label.Uint("uint8", uint(uint8Val))
52
53	uint16Val    = uint16(1)
54	uint16KeyVal = label.Uint("uint16", uint(uint16Val))
55
56	uint32Val    = uint32(1)
57	uint32KeyVal = label.Uint32("uint32", uint32Val)
58
59	uint64Val    = uint64(1)
60	uint64KeyVal = label.Uint64("uint64", uint64Val)
61
62	float32Val    = float32(1.0)
63	float32KeyVal = label.Float32("float32", float32Val)
64
65	float64Val    = float64(1.0)
66	float64KeyVal = label.Float64("float64", float64Val)
67
68	stringVal    = "string"
69	stringKeyVal = label.String("string", stringVal)
70
71	bytesVal  = []byte("bytes")
72	structVal = test{}
73)
74
75func BenchmarkArrayKey(b *testing.B) {
76	b.ReportAllocs()
77	for i := 0; i < b.N; i++ {
78		_ = label.Array("array", arrayVal)
79	}
80}
81
82func BenchmarkArrayKeyAny(b *testing.B) {
83	b.ReportAllocs()
84	for i := 0; i < b.N; i++ {
85		_ = label.Any("array", arrayVal)
86	}
87}
88
89func BenchmarkBoolKey(b *testing.B) {
90	b.ReportAllocs()
91	for i := 0; i < b.N; i++ {
92		_ = label.Bool("bool", boolVal)
93	}
94}
95
96func BenchmarkBoolKeyAny(b *testing.B) {
97	b.ReportAllocs()
98	for i := 0; i < b.N; i++ {
99		_ = label.Any("bool", boolVal)
100	}
101}
102
103func BenchmarkIntKey(b *testing.B) {
104	b.ReportAllocs()
105	for i := 0; i < b.N; i++ {
106		_ = label.Int("int", intVal)
107	}
108}
109
110func BenchmarkIntKeyAny(b *testing.B) {
111	b.ReportAllocs()
112	for i := 0; i < b.N; i++ {
113		_ = label.Any("int", intVal)
114	}
115}
116
117func BenchmarkInt8KeyAny(b *testing.B) {
118	b.ReportAllocs()
119	for i := 0; i < b.N; i++ {
120		_ = label.Any("int8", int8Val)
121	}
122}
123
124func BenchmarkInt16KeyAny(b *testing.B) {
125	b.ReportAllocs()
126	for i := 0; i < b.N; i++ {
127		_ = label.Any("int16", int16Val)
128	}
129}
130
131func BenchmarkInt32Key(b *testing.B) {
132	b.ReportAllocs()
133	for i := 0; i < b.N; i++ {
134		_ = label.Int32("int32", int32Val)
135	}
136}
137
138func BenchmarkInt32KeyAny(b *testing.B) {
139	b.ReportAllocs()
140	for i := 0; i < b.N; i++ {
141		_ = label.Any("int32", int32Val)
142	}
143}
144
145func BenchmarkInt64Key(b *testing.B) {
146	b.ReportAllocs()
147	for i := 0; i < b.N; i++ {
148		_ = label.Int64("int64", int64Val)
149	}
150}
151
152func BenchmarkInt64KeyAny(b *testing.B) {
153	b.ReportAllocs()
154	for i := 0; i < b.N; i++ {
155		_ = label.Any("int64", int64Val)
156	}
157}
158
159func BenchmarkUintKey(b *testing.B) {
160	b.ReportAllocs()
161	for i := 0; i < b.N; i++ {
162		_ = label.Uint("uint", uintVal)
163	}
164}
165
166func BenchmarkUintKeyAny(b *testing.B) {
167	b.ReportAllocs()
168	for i := 0; i < b.N; i++ {
169		_ = label.Any("uint", uintVal)
170	}
171}
172
173func BenchmarkUint8KeyAny(b *testing.B) {
174	b.ReportAllocs()
175	for i := 0; i < b.N; i++ {
176		_ = label.Any("uint8", uint8Val)
177	}
178}
179
180func BenchmarkUint16KeyAny(b *testing.B) {
181	b.ReportAllocs()
182	for i := 0; i < b.N; i++ {
183		_ = label.Any("uint16", uint16Val)
184	}
185}
186
187func BenchmarkUint32Key(b *testing.B) {
188	b.ReportAllocs()
189	for i := 0; i < b.N; i++ {
190		_ = label.Uint32("uint32", uint32Val)
191	}
192}
193
194func BenchmarkUint32KeyAny(b *testing.B) {
195	b.ReportAllocs()
196	for i := 0; i < b.N; i++ {
197		_ = label.Any("uint32", uint32Val)
198	}
199}
200
201func BenchmarkUint64Key(b *testing.B) {
202	b.ReportAllocs()
203	for i := 0; i < b.N; i++ {
204		_ = label.Uint64("uint64", uint64Val)
205	}
206}
207
208func BenchmarkUint64KeyAny(b *testing.B) {
209	b.ReportAllocs()
210	for i := 0; i < b.N; i++ {
211		_ = label.Any("uint64", uint64Val)
212	}
213}
214
215func BenchmarkFloat32Key(b *testing.B) {
216	b.ReportAllocs()
217	for i := 0; i < b.N; i++ {
218		_ = label.Float32("float32", float32Val)
219	}
220}
221
222func BenchmarkFloat32KeyAny(b *testing.B) {
223	b.ReportAllocs()
224	for i := 0; i < b.N; i++ {
225		_ = label.Any("float32", float32Val)
226	}
227}
228
229func BenchmarkFloat64Key(b *testing.B) {
230	b.ReportAllocs()
231	for i := 0; i < b.N; i++ {
232		_ = label.Float64("float64", float64Val)
233	}
234}
235
236func BenchmarkFloat64KeyAny(b *testing.B) {
237	b.ReportAllocs()
238	for i := 0; i < b.N; i++ {
239		_ = label.Any("float64", float64Val)
240	}
241}
242
243func BenchmarkStringKey(b *testing.B) {
244	b.ReportAllocs()
245	for i := 0; i < b.N; i++ {
246		_ = label.String("string", stringVal)
247	}
248}
249
250func BenchmarkStringKeyAny(b *testing.B) {
251	b.ReportAllocs()
252	for i := 0; i < b.N; i++ {
253		_ = label.Any("string", stringVal)
254	}
255}
256
257func BenchmarkBytesKeyAny(b *testing.B) {
258	b.ReportAllocs()
259	for i := 0; i < b.N; i++ {
260		_ = label.Any("bytes", bytesVal)
261	}
262}
263
264func BenchmarkStructKeyAny(b *testing.B) {
265	b.ReportAllocs()
266	for i := 0; i < b.N; i++ {
267		_ = label.Any("struct", structVal)
268	}
269}
270
271func BenchmarkEmitArray(b *testing.B) {
272	b.ReportAllocs()
273	for i := 0; i < b.N; i++ {
274		_ = arrayKeyVal.Value.Emit()
275	}
276}
277
278func BenchmarkEmitBool(b *testing.B) {
279	b.ReportAllocs()
280	for i := 0; i < b.N; i++ {
281		_ = boolKeyVal.Value.Emit()
282	}
283}
284
285func BenchmarkEmitInt(b *testing.B) {
286	b.ReportAllocs()
287	for i := 0; i < b.N; i++ {
288		_ = intKeyVal.Value.Emit()
289	}
290}
291
292func BenchmarkEmitInt8(b *testing.B) {
293	b.ReportAllocs()
294	for i := 0; i < b.N; i++ {
295		_ = int8KeyVal.Value.Emit()
296	}
297}
298
299func BenchmarkEmitInt16(b *testing.B) {
300	b.ReportAllocs()
301	for i := 0; i < b.N; i++ {
302		_ = int16KeyVal.Value.Emit()
303	}
304}
305
306func BenchmarkEmitInt32(b *testing.B) {
307	b.ReportAllocs()
308	for i := 0; i < b.N; i++ {
309		_ = int32KeyVal.Value.Emit()
310	}
311}
312
313func BenchmarkEmitInt64(b *testing.B) {
314	b.ReportAllocs()
315	for i := 0; i < b.N; i++ {
316		_ = int64KeyVal.Value.Emit()
317	}
318}
319
320func BenchmarkEmitUint(b *testing.B) {
321	b.ReportAllocs()
322	for i := 0; i < b.N; i++ {
323		_ = uintKeyVal.Value.Emit()
324	}
325}
326
327func BenchmarkEmitUint8(b *testing.B) {
328	b.ReportAllocs()
329	for i := 0; i < b.N; i++ {
330		_ = uint8KeyVal.Value.Emit()
331	}
332}
333
334func BenchmarkEmitUint16(b *testing.B) {
335	b.ReportAllocs()
336	for i := 0; i < b.N; i++ {
337		_ = uint16KeyVal.Value.Emit()
338	}
339}
340
341func BenchmarkEmitUint32(b *testing.B) {
342	b.ReportAllocs()
343	for i := 0; i < b.N; i++ {
344		_ = uint32KeyVal.Value.Emit()
345	}
346}
347
348func BenchmarkEmitUint64(b *testing.B) {
349	b.ReportAllocs()
350	for i := 0; i < b.N; i++ {
351		_ = uint64KeyVal.Value.Emit()
352	}
353}
354
355func BenchmarkEmitFloat32(b *testing.B) {
356	b.ReportAllocs()
357	for i := 0; i < b.N; i++ {
358		_ = float32KeyVal.Value.Emit()
359	}
360}
361
362func BenchmarkEmitFloat64(b *testing.B) {
363	b.ReportAllocs()
364	for i := 0; i < b.N; i++ {
365		_ = float64KeyVal.Value.Emit()
366	}
367}
368
369func BenchmarkEmitString(b *testing.B) {
370	b.ReportAllocs()
371	for i := 0; i < b.N; i++ {
372		_ = stringKeyVal.Value.Emit()
373	}
374}
375