Skip to content
This repository has been archived by the owner on Jul 31, 2023. It is now read-only.

Commit

Permalink
Add a benchmark for stats.WithMeter (but with no views registered)
Browse files Browse the repository at this point in the history
Signed-off-by: Evan Anderson <evan.k.anderson@gmail.com>
  • Loading branch information
evankanderson committed Feb 13, 2020
1 parent 4ffaf99 commit 73c05bf
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions stats/benchmark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"testing"

"go.opencensus.io/stats"
"go.opencensus.io/stats/view"
_ "go.opencensus.io/stats/view" // enable collection
"go.opencensus.io/tag"
)
Expand Down Expand Up @@ -52,6 +53,22 @@ func BenchmarkRecord8(b *testing.B) {
}
}

func BenchmarkRecord8_WithRecorder(b *testing.B) {
ctx := context.Background()
meter := view.NewMeter()
meter.Start()
defer meter.Stop()
b.ResetTimer()

for i := 0; i < b.N; i++ {
// Note that this benchmark has one extra allocation for stats.WithRecorder.
// If you cache the recorder option, this benchmark should be equally fast as BenchmarkRecord8
stats.RecordWithOptions(ctx, stats.WithRecorder(meter), stats.WithMeasurements(m.M(1), m.M(1), m.M(1), m.M(1), m.M(1), m.M(1), m.M(1), m.M(1)))
}

b.StopTimer()
}

func BenchmarkRecord8_Parallel(b *testing.B) {
ctx := context.Background()
b.ResetTimer()
Expand Down

0 comments on commit 73c05bf

Please sign in to comment.