@@ -272,6 +272,59 @@ func BenchmarkStringSlice(b *testing.B) {
272
272
b .Run ("Emit" , benchmarkEmit (kv ))
273
273
}
274
274
275
+ func BenchmarkSetEquals (b * testing.B ) {
276
+ b .Run ("Empty" , func (b * testing.B ) {
277
+ benchmarkSetEquals (b , attribute .EmptySet ())
278
+ })
279
+ b .Run ("1 string attribute" , func (b * testing.B ) {
280
+ set := attribute .NewSet (attribute .String ("string" , "42" ))
281
+ benchmarkSetEquals (b , & set )
282
+ })
283
+ b .Run ("10 string attributes" , func (b * testing.B ) {
284
+ set := attribute .NewSet (
285
+ attribute .String ("a" , "42" ),
286
+ attribute .String ("b" , "42" ),
287
+ attribute .String ("c" , "42" ),
288
+ attribute .String ("d" , "42" ),
289
+ attribute .String ("e" , "42" ),
290
+ attribute .String ("f" , "42" ),
291
+ attribute .String ("g" , "42" ),
292
+ attribute .String ("h" , "42" ),
293
+ attribute .String ("i" , "42" ),
294
+ attribute .String ("j" , "42" ),
295
+ )
296
+ benchmarkSetEquals (b , & set )
297
+ })
298
+ b .Run ("1 int attribute" , func (b * testing.B ) {
299
+ set := attribute .NewSet (attribute .Int ("string" , 42 ))
300
+ benchmarkSetEquals (b , & set )
301
+ })
302
+ b .Run ("10 int attributes" , func (b * testing.B ) {
303
+ set := attribute .NewSet (
304
+ attribute .Int ("a" , 42 ),
305
+ attribute .Int ("b" , 42 ),
306
+ attribute .Int ("c" , 42 ),
307
+ attribute .Int ("d" , 42 ),
308
+ attribute .Int ("e" , 42 ),
309
+ attribute .Int ("f" , 42 ),
310
+ attribute .Int ("g" , 42 ),
311
+ attribute .Int ("h" , 42 ),
312
+ attribute .Int ("i" , 42 ),
313
+ attribute .Int ("j" , 42 ),
314
+ )
315
+ benchmarkSetEquals (b , & set )
316
+ })
317
+ }
318
+
319
+ func benchmarkSetEquals (b * testing.B , set * attribute.Set ) {
320
+ b .ResetTimer ()
321
+ for range b .N {
322
+ if ! set .Equals (set ) {
323
+ b .Fatal ("not equal" )
324
+ }
325
+ }
326
+ }
327
+
275
328
// BenchmarkEquivalentMapAccess measures how expensive it is to use
276
329
// Equivalent() as a map key. This is on the hot path for making synchronous
277
330
// measurements on the metrics API/SDK. It will likely be on the hot path for
0 commit comments