Skip to content

Commit 0724539

Browse files
dashpoleflc1125pellared
authored
Add benchmark for set equality (#7262)
Forked from #7175 ``` $ go test -timeout 60s -run=xxxxxMatchNothingxxxxx -test.benchtime=10ms -count 6 -cpu 1 -bench=BenchmarkEquals ./... goos: linux goarch: amd64 pkg: go.opentelemetry.io/otel/attribute cpu: Intel(R) Xeon(R) CPU @ 2.20GHz BenchmarkEquals/Empty 1314884 9.008 ns/op BenchmarkEquals/Empty 1875915 8.461 ns/op BenchmarkEquals/Empty 1461613 7.749 ns/op BenchmarkEquals/Empty 1636912 9.359 ns/op BenchmarkEquals/Empty 1863039 6.355 ns/op BenchmarkEquals/Empty 1789053 6.336 ns/op BenchmarkEquals/1_string_attribute 674168 16.92 ns/op BenchmarkEquals/1_string_attribute 701983 16.42 ns/op BenchmarkEquals/1_string_attribute 692001 16.52 ns/op BenchmarkEquals/1_string_attribute 687970 16.29 ns/op BenchmarkEquals/1_string_attribute 751766 16.58 ns/op BenchmarkEquals/1_string_attribute 703534 16.88 ns/op BenchmarkEquals/10_string_attributes 85400 137.1 ns/op BenchmarkEquals/10_string_attributes 91045 136.1 ns/op BenchmarkEquals/10_string_attributes 90973 150.7 ns/op BenchmarkEquals/10_string_attributes 62877 177.5 ns/op BenchmarkEquals/10_string_attributes 90780 194.2 ns/op BenchmarkEquals/10_string_attributes 91058 144.6 ns/op BenchmarkEquals/1_int_attribute 624625 18.72 ns/op BenchmarkEquals/1_int_attribute 689478 16.03 ns/op BenchmarkEquals/1_int_attribute 719173 15.68 ns/op BenchmarkEquals/1_int_attribute 707005 16.18 ns/op BenchmarkEquals/1_int_attribute 752048 15.94 ns/op BenchmarkEquals/1_int_attribute 752034 16.23 ns/op BenchmarkEquals/10_int_attributes 90302 132.5 ns/op BenchmarkEquals/10_int_attributes 89929 131.9 ns/op BenchmarkEquals/10_int_attributes 86578 135.2 ns/op BenchmarkEquals/10_int_attributes 90482 133.1 ns/op BenchmarkEquals/10_int_attributes 90255 132.0 ns/op BenchmarkEquals/10_int_attributes 87615 134.6 ns/op PASS ok go.opentelemetry.io/otel/attribute 0.578s PASS ok go.opentelemetry.io/otel/attribute/internal 0.017s ``` --------- Co-authored-by: Flc゛ <[email protected]> Co-authored-by: Robert Pająk <[email protected]>
1 parent 5358fd7 commit 0724539

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

attribute/benchmark_test.go

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,59 @@ func BenchmarkStringSlice(b *testing.B) {
272272
b.Run("Emit", benchmarkEmit(kv))
273273
}
274274

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+
275328
// BenchmarkEquivalentMapAccess measures how expensive it is to use
276329
// Equivalent() as a map key. This is on the hot path for making synchronous
277330
// measurements on the metrics API/SDK. It will likely be on the hot path for

0 commit comments

Comments
 (0)