Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions attribute/benchmark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,3 +271,59 @@ func BenchmarkStringSlice(b *testing.B) {
})
b.Run("Emit", benchmarkEmit(kv))
}

// BenchmarkEquivalentMapAccess measures how expensive it is to use
// Equivalent() as a map key. This is on the hot path for making synchronous
// measurements on the metrics API/SDK. It will likely be on the hot path for
// the trace and logs API/SDK in the future.
func BenchmarkEquivalentMapAccess(b *testing.B) {
b.Run("Empty", func(b *testing.B) {
benchmarkEquivalentMapAccess(b, attribute.EmptySet())
})
b.Run("1 string attribute", func(b *testing.B) {
set := attribute.NewSet(attribute.String("string", "42"))
benchmarkEquivalentMapAccess(b, &set)
})
b.Run("10 string attributes", func(b *testing.B) {
set := attribute.NewSet(
attribute.String("a", "42"),
attribute.String("b", "42"),
attribute.String("c", "42"),
attribute.String("d", "42"),
attribute.String("e", "42"),
attribute.String("f", "42"),
attribute.String("g", "42"),
attribute.String("h", "42"),
attribute.String("i", "42"),
attribute.String("j", "42"),
)
benchmarkEquivalentMapAccess(b, &set)
})
b.Run("1 int attribute", func(b *testing.B) {
set := attribute.NewSet(attribute.Int("string", 42))
benchmarkEquivalentMapAccess(b, &set)
})
b.Run("10 int attributes", func(b *testing.B) {
set := attribute.NewSet(
attribute.Int("a", 42),
attribute.Int("b", 42),
attribute.Int("c", 42),
attribute.Int("d", 42),
attribute.Int("e", 42),
attribute.Int("f", 42),
attribute.Int("g", 42),
attribute.Int("h", 42),
attribute.Int("i", 42),
attribute.Int("j", 42),
)
benchmarkEquivalentMapAccess(b, &set)
})
}

func benchmarkEquivalentMapAccess(b *testing.B, set *attribute.Set) {
values := map[attribute.Distinct]int{}
b.ResetTimer()
for range b.N {
values[set.Equivalent()]++
}
}
Loading