Skip to content

Commit 567ef26

Browse files
authored
Add benchmark for exponential histogram measurements (#7305)
This is helpful for my work optimizing locking in #7189 ``` goos: linux goarch: amd64 pkg: go.opentelemetry.io/otel/sdk/metric cpu: Intel(R) Xeon(R) CPU @ 2.20GHz BenchmarkSyncMeasure/NoView/ExponentialFloat64Histogram/Attributes/0-24 43419 306.0 ns/op 0 B/op 0 allocs/op BenchmarkSyncMeasure/NoView/ExponentialFloat64Histogram/Attributes/0-24 40675 316.1 ns/op 0 B/op 0 allocs/op BenchmarkSyncMeasure/NoView/ExponentialFloat64Histogram/Attributes/0-24 53746 305.6 ns/op 0 B/op 0 allocs/op BenchmarkSyncMeasure/NoView/ExponentialFloat64Histogram/Attributes/0-24 38224 296.1 ns/op 0 B/op 0 allocs/op BenchmarkSyncMeasure/NoView/ExponentialFloat64Histogram/Attributes/0-24 53796 330.3 ns/op 0 B/op 0 allocs/op BenchmarkSyncMeasure/NoView/ExponentialFloat64Histogram/Attributes/0-24 47823 316.4 ns/op 0 B/op 0 allocs/op BenchmarkSyncMeasure/NoView/ExponentialFloat64Histogram/Attributes/1-24 32172 373.5 ns/op 0 B/op 0 allocs/op BenchmarkSyncMeasure/NoView/ExponentialFloat64Histogram/Attributes/1-24 33084 379.0 ns/op 0 B/op 0 allocs/op BenchmarkSyncMeasure/NoView/ExponentialFloat64Histogram/Attributes/1-24 29956 360.4 ns/op 0 B/op 0 allocs/op BenchmarkSyncMeasure/NoView/ExponentialFloat64Histogram/Attributes/1-24 33921 370.1 ns/op 0 B/op 0 allocs/op BenchmarkSyncMeasure/NoView/ExponentialFloat64Histogram/Attributes/1-24 34449 387.7 ns/op 0 B/op 0 allocs/op BenchmarkSyncMeasure/NoView/ExponentialFloat64Histogram/Attributes/1-24 29156 393.6 ns/op 0 B/op 0 allocs/op BenchmarkSyncMeasure/NoView/ExponentialFloat64Histogram/Attributes/10-24 10768 1040 ns/op 0 B/op 0 allocs/op BenchmarkSyncMeasure/NoView/ExponentialFloat64Histogram/Attributes/10-24 11190 1056 ns/op 0 B/op 0 allocs/op BenchmarkSyncMeasure/NoView/ExponentialFloat64Histogram/Attributes/10-24 11078 1176 ns/op 0 B/op 0 allocs/op BenchmarkSyncMeasure/NoView/ExponentialFloat64Histogram/Attributes/10-24 10929 1219 ns/op 0 B/op 0 allocs/op BenchmarkSyncMeasure/NoView/ExponentialFloat64Histogram/Attributes/10-24 10454 1066 ns/op 0 B/op 0 allocs/op BenchmarkSyncMeasure/NoView/ExponentialFloat64Histogram/Attributes/10-24 10501 1064 ns/op 0 B/op 0 allocs/op BenchmarkSyncMeasure/DropView/ExponentialFloat64Histogram/Attributes/0-24 5919898 1.879 ns/op 0 B/op 0 allocs/op BenchmarkSyncMeasure/DropView/ExponentialFloat64Histogram/Attributes/0-24 5834685 1.990 ns/op 0 B/op 0 allocs/op BenchmarkSyncMeasure/DropView/ExponentialFloat64Histogram/Attributes/0-24 5782334 2.433 ns/op 0 B/op 0 allocs/op BenchmarkSyncMeasure/DropView/ExponentialFloat64Histogram/Attributes/0-24 5320924 2.404 ns/op 0 B/op 0 allocs/op BenchmarkSyncMeasure/DropView/ExponentialFloat64Histogram/Attributes/0-24 5742800 2.109 ns/op 0 B/op 0 allocs/op BenchmarkSyncMeasure/DropView/ExponentialFloat64Histogram/Attributes/0-24 5885475 2.056 ns/op 0 B/op 0 allocs/op BenchmarkSyncMeasure/DropView/ExponentialFloat64Histogram/Attributes/1-24 4331547 2.758 ns/op 0 B/op 0 allocs/op BenchmarkSyncMeasure/DropView/ExponentialFloat64Histogram/Attributes/1-24 3848244 2.725 ns/op 0 B/op 0 allocs/op BenchmarkSyncMeasure/DropView/ExponentialFloat64Histogram/Attributes/1-24 4542189 2.636 ns/op 0 B/op 0 allocs/op BenchmarkSyncMeasure/DropView/ExponentialFloat64Histogram/Attributes/1-24 4201015 2.641 ns/op 0 B/op 0 allocs/op BenchmarkSyncMeasure/DropView/ExponentialFloat64Histogram/Attributes/1-24 4597094 2.608 ns/op 0 B/op 0 allocs/op BenchmarkSyncMeasure/DropView/ExponentialFloat64Histogram/Attributes/1-24 4869811 2.491 ns/op 0 B/op 0 allocs/op BenchmarkSyncMeasure/DropView/ExponentialFloat64Histogram/Attributes/10-24 4826077 2.329 ns/op 0 B/op 0 allocs/op BenchmarkSyncMeasure/DropView/ExponentialFloat64Histogram/Attributes/10-24 4866612 2.382 ns/op 0 B/op 0 allocs/op BenchmarkSyncMeasure/DropView/ExponentialFloat64Histogram/Attributes/10-24 5149305 2.310 ns/op 0 B/op 0 allocs/op BenchmarkSyncMeasure/DropView/ExponentialFloat64Histogram/Attributes/10-24 5101305 2.384 ns/op 0 B/op 0 allocs/op BenchmarkSyncMeasure/DropView/ExponentialFloat64Histogram/Attributes/10-24 4854940 2.440 ns/op 0 B/op 0 allocs/op BenchmarkSyncMeasure/DropView/ExponentialFloat64Histogram/Attributes/10-24 4874742 2.501 ns/op 0 B/op 0 allocs/op BenchmarkSyncMeasure/AttrFilterView/ExponentialFloat64Histogram/Attributes/0-24 55272 359.0 ns/op 0 B/op 0 allocs/op BenchmarkSyncMeasure/AttrFilterView/ExponentialFloat64Histogram/Attributes/0-24 52195 318.4 ns/op 0 B/op 0 allocs/op BenchmarkSyncMeasure/AttrFilterView/ExponentialFloat64Histogram/Attributes/0-24 52324 330.8 ns/op 0 B/op 0 allocs/op BenchmarkSyncMeasure/AttrFilterView/ExponentialFloat64Histogram/Attributes/0-24 49879 321.4 ns/op 0 B/op 0 allocs/op BenchmarkSyncMeasure/AttrFilterView/ExponentialFloat64Histogram/Attributes/0-24 56212 351.3 ns/op 0 B/op 0 allocs/op BenchmarkSyncMeasure/AttrFilterView/ExponentialFloat64Histogram/Attributes/0-24 43362 301.4 ns/op 0 B/op 0 allocs/op BenchmarkSyncMeasure/AttrFilterView/ExponentialFloat64Histogram/Attributes/1-24 30296 461.9 ns/op 0 B/op 0 allocs/op BenchmarkSyncMeasure/AttrFilterView/ExponentialFloat64Histogram/Attributes/1-24 24178 469.0 ns/op 0 B/op 0 allocs/op BenchmarkSyncMeasure/AttrFilterView/ExponentialFloat64Histogram/Attributes/1-24 24901 477.0 ns/op 0 B/op 0 allocs/op BenchmarkSyncMeasure/AttrFilterView/ExponentialFloat64Histogram/Attributes/1-24 21748 477.6 ns/op 0 B/op 0 allocs/op BenchmarkSyncMeasure/AttrFilterView/ExponentialFloat64Histogram/Attributes/1-24 23972 512.9 ns/op 0 B/op 0 allocs/op BenchmarkSyncMeasure/AttrFilterView/ExponentialFloat64Histogram/Attributes/1-24 28039 499.5 ns/op 0 B/op 0 allocs/op BenchmarkSyncMeasure/AttrFilterView/ExponentialFloat64Histogram/Attributes/10-24 7598 1646 ns/op 704 B/op 2 allocs/op BenchmarkSyncMeasure/AttrFilterView/ExponentialFloat64Histogram/Attributes/10-24 7452 1660 ns/op 704 B/op 2 allocs/op BenchmarkSyncMeasure/AttrFilterView/ExponentialFloat64Histogram/Attributes/10-24 7620 1644 ns/op 704 B/op 2 allocs/op BenchmarkSyncMeasure/AttrFilterView/ExponentialFloat64Histogram/Attributes/10-24 6459 1853 ns/op 704 B/op 2 allocs/op BenchmarkSyncMeasure/AttrFilterView/ExponentialFloat64Histogram/Attributes/10-24 7950 1575 ns/op 704 B/op 2 allocs/op BenchmarkSyncMeasure/AttrFilterView/ExponentialFloat64Histogram/Attributes/10-24 8948 1421 ns/op 704 B/op 2 allocs/op ```
1 parent 8ac554a commit 567ef26

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

sdk/metric/benchmark_test.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,21 @@ func BenchmarkSyncMeasure(b *testing.B) {
4545
}
4646
}
4747

48+
func exponentialAggregationSelector(ik InstrumentKind) Aggregation {
49+
if ik == InstrumentKindHistogram {
50+
return AggregationBase2ExponentialHistogram{MaxScale: 20, MaxSize: 160}
51+
}
52+
return AggregationDefault{}
53+
}
54+
4855
func benchSyncViews(views ...View) func(*testing.B) {
4956
ctx := context.Background()
5057
rdr := NewManualReader()
5158
provider := NewMeterProvider(WithReader(rdr), WithView(views...))
5259
meter := provider.Meter("benchSyncViews")
60+
expRdr := NewManualReader(WithAggregationSelector(exponentialAggregationSelector))
61+
expProvider := NewMeterProvider(WithReader(expRdr), WithView(views...))
62+
expMeter := expProvider.Meter("benchSyncViews")
5363
return func(b *testing.B) {
5464
iCtr, err := meter.Int64Counter("int64-counter")
5565
assert.NoError(b, err)
@@ -104,6 +114,24 @@ func benchSyncViews(views ...View) func(*testing.B) {
104114
return func() { fHist.Record(ctx, 1, o...) }
105115
}
106116
}()))
117+
118+
expIHist, err := expMeter.Int64Histogram("exponential-int64-histogram")
119+
assert.NoError(b, err)
120+
b.Run("ExponentialInt64Histogram", benchMeasAttrs(func() measF {
121+
return func(s attribute.Set) func() {
122+
o := []metric.RecordOption{metric.WithAttributeSet(s)}
123+
return func() { expIHist.Record(ctx, 1, o...) }
124+
}
125+
}()))
126+
127+
expFHist, err := expMeter.Float64Histogram("exponential-float64-histogram")
128+
assert.NoError(b, err)
129+
b.Run("ExponentialFloat64Histogram", benchMeasAttrs(func() measF {
130+
return func(s attribute.Set) func() {
131+
o := []metric.RecordOption{metric.WithAttributeSet(s)}
132+
return func() { expFHist.Record(ctx, 1, o...) }
133+
}
134+
}()))
107135
}
108136
}
109137

0 commit comments

Comments
 (0)