Skip to content

Commit

Permalink
Add benchmark metric test for UpDownCounter (#2655)
Browse files Browse the repository at this point in the history
* add benchmark metric test for UpDownCounter

* move counter annotation up

* fix syncFloat64 to syncInt64

* fix syncFloat64 to syncInt64

* fix go-lint err
  • Loading branch information
hanyuancheung authored Jul 12, 2022
1 parent 08ff959 commit f739569
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions sdk/metric/benchmark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,20 +66,39 @@ 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 {
f.B.Error(err)
}
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 {
f.B.Error(err)
}
return ctr
}

func (f *benchFixture) fHistogram(name string) syncfloat64.Histogram {
ctr, err := f.meter.SyncFloat64().Histogram(name)
if err != nil {
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit f739569

Please sign in to comment.