Skip to content

Commit 2e0b5b4

Browse files
authored
Add benchmark for synchronous gauge measurement (#7407)
These were missing from our benchmarks for synchronous instruments. Single-threaded: ``` goos: linux goarch: amd64 pkg: go.opentelemetry.io/otel/sdk/metric cpu: Intel(R) Xeon(R) CPU @ 2.20GHz BenchmarkSyncMeasure/NoView/Float64Gauge/Attributes/0 114369 106.0 ns/op 0 B/op 0 allocs/op BenchmarkSyncMeasure/NoView/Float64Gauge/Attributes/1 106424 119.4 ns/op 0 B/op 0 allocs/op BenchmarkSyncMeasure/NoView/Float64Gauge/Attributes/10 79513 128.7 ns/op 0 B/op 0 allocs/op BenchmarkSyncMeasure/NoView/Int64Gauge/Attributes/0 110667 166.0 ns/op 0 B/op 0 allocs/op BenchmarkSyncMeasure/NoView/Int64Gauge/Attributes/1 103809 150.2 ns/op 0 B/op 0 allocs/op BenchmarkSyncMeasure/NoView/Int64Gauge/Attributes/10 76430 144.2 ns/op 0 B/op 0 allocs/op ``` Parallel: ``` goos: linux goarch: amd64 pkg: go.opentelemetry.io/otel/sdk/metric cpu: Intel(R) Xeon(R) CPU @ 2.20GHz BenchmarkSyncMeasure/NoView/Float64Gauge/Attributes/0-24 40507 283.4 ns/op 0 B/op 0 allocs/op BenchmarkSyncMeasure/NoView/Float64Gauge/Attributes/1-24 43918 305.3 ns/op 0 B/op 0 allocs/op BenchmarkSyncMeasure/NoView/Float64Gauge/Attributes/10-24 41348 291.0 ns/op 0 B/op 0 allocs/op BenchmarkSyncMeasure/NoView/Int64Gauge/Attributes/0-24 48070 291.1 ns/op 0 B/op 0 allocs/op BenchmarkSyncMeasure/NoView/Int64Gauge/Attributes/1-24 43290 274.9 ns/op 0 B/op 0 allocs/op BenchmarkSyncMeasure/NoView/Int64Gauge/Attributes/10-24 40003 325.0 ns/op 0 B/op 0 allocs/op ```
1 parent 97e2244 commit 2e0b5b4

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

sdk/metric/benchmark_test.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,24 @@ func benchSyncViews(views ...View) func(*testing.B) {
9696
}
9797
}()))
9898

99+
iGauge, err := meter.Int64Gauge("int64-gauge")
100+
assert.NoError(b, err)
101+
b.Run("Int64Gauge", benchMeasAttrs(func() measF {
102+
return func(s attribute.Set) func() {
103+
o := []metric.RecordOption{metric.WithAttributeSet(s)}
104+
return func() { iGauge.Record(b.Context(), 1, o...) }
105+
}
106+
}()))
107+
108+
fGauge, err := meter.Float64Gauge("float64-gauge")
109+
assert.NoError(b, err)
110+
b.Run("Float64Gauge", benchMeasAttrs(func() measF {
111+
return func(s attribute.Set) func() {
112+
o := []metric.RecordOption{metric.WithAttributeSet(s)}
113+
return func() { fGauge.Record(b.Context(), 1, o...) }
114+
}
115+
}()))
116+
99117
iHist, err := meter.Int64Histogram("int64-histogram")
100118
assert.NoError(b, err)
101119
b.Run("Int64Histogram", benchMeasAttrs(func() measF {

0 commit comments

Comments
 (0)