1
0
mirror of https://github.com/open-telemetry/opentelemetry-go.git synced 2026-06-03 18:35:08 +02:00

Add benchmark metric test for UpDownCounter (#2655)

* add benchmark metric test for UpDownCounter

* move counter annotation up

* fix syncFloat64 to syncInt64

* fix syncFloat64 to syncInt64

* fix go-lint err
This commit is contained in:
Chester Cheung
2022-07-13 03:12:58 +08:00
committed by GitHub
parent 08ff959fc4
commit f7395695b7
+47
View File
@@ -66,6 +66,7 @@ func (f *benchFixture) iCounter(name string) syncint64.Counter {
}
return ctr
}
func (f *benchFixture) fCounter(name string) syncfloat64.Counter {
ctr, err := f.meter.SyncFloat64().Counter(name)
if err != nil {
@@ -73,6 +74,23 @@ func (f *benchFixture) fCounter(name string) syncfloat64.Counter {
}
return ctr
}
func (f *benchFixture) iUpDownCounter(name string) syncint64.UpDownCounter {
ctr, err := f.meter.SyncInt64().UpDownCounter(name)
if err != nil {
f.B.Error(err)
}
return ctr
}
func (f *benchFixture) fUpDownCounter(name string) syncfloat64.UpDownCounter {
ctr, err := f.meter.SyncFloat64().UpDownCounter(name)
if err != nil {
f.B.Error(err)
}
return ctr
}
func (f *benchFixture) iHistogram(name string) syncint64.Histogram {
ctr, err := f.meter.SyncInt64().Histogram(name)
if err != nil {
@@ -80,6 +98,7 @@ func (f *benchFixture) iHistogram(name string) syncint64.Histogram {
}
return ctr
}
func (f *benchFixture) fHistogram(name string) syncfloat64.Histogram {
ctr, err := f.meter.SyncFloat64().Histogram(name)
if err != nil {
@@ -228,6 +247,34 @@ func BenchmarkFloat64CounterAdd(b *testing.B) {
}
}
// UpDownCounter
func BenchmarkInt64UpDownCounterAdd(b *testing.B) {
ctx := context.Background()
fix := newFixture(b)
labs := makeAttrs(1)
cnt := fix.iUpDownCounter("int64.sum")
b.ResetTimer()
for i := 0; i < b.N; i++ {
cnt.Add(ctx, 1, labs...)
}
}
func BenchmarkFloat64UpDownCounterAdd(b *testing.B) {
ctx := context.Background()
fix := newFixture(b)
labs := makeAttrs(1)
cnt := fix.fUpDownCounter("float64.sum")
b.ResetTimer()
for i := 0; i < b.N; i++ {
cnt.Add(ctx, 1.1, labs...)
}
}
// LastValue
func BenchmarkInt64LastValueAdd(b *testing.B) {