Skip to content

Commit

Permalink
add benchmark for recording status code
Browse files Browse the repository at this point in the history
On a 3ghz intel CPU we do zero allocs and record takes 255ns.
  • Loading branch information
sbunce committed Nov 6, 2020
1 parent 58cc5ad commit a71cfa1
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions memmetrics/roundtrip_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,25 @@ import (
"github.com/vulcand/oxy/testutils"
)

func BenchmarkRecord(b *testing.B) {
b.ReportAllocs()

rr, err := NewRTMetrics(RTClock(testutils.GetClock()))
require.NoError(b, err)

// warm up metrics. Adding a new code can do allocations, but in the steady
// state recording a code is cheap. We want to measure the steady state.
const codes = 100
for code := 0; code < codes; code++ {
rr.Record(code, time.Second)
}

b.ResetTimer()
for i := 0; i < b.N; i++ {
rr.Record(i%codes, time.Second)
}
}

func TestDefaults(t *testing.T) {
rr, err := NewRTMetrics(RTClock(testutils.GetClock()))
require.NoError(t, err)
Expand Down

0 comments on commit a71cfa1

Please sign in to comment.