Browse Source

web: Add benchmark for respond()

pull/3995/head
Brian Brazil 7 years ago
parent
commit
ecd0a9c6ba
  1. 23
      web/api/v1/api_test.go

23
web/api/v1/api_test.go

@ -853,3 +853,26 @@ func TestOptionsMethod(t *testing.T) {
}
}
}
// This is a global to avoid the benchmark being optimized away.
var testResponseWriter = httptest.ResponseRecorder{}
func BenchmarkRespond(b *testing.B) {
b.ReportAllocs()
points := []promql.Point{}
for i := 0; i < 10000; i++ {
points = append(points, promql.Point{V: float64(i * 1000000), T: int64(i)})
}
response := &queryData{
ResultType: promql.ValueTypeMatrix,
Result: promql.Matrix{
promql.Series{
Points: points,
Metric: nil,
},
},
}
for n := 0; n < b.N; n++ {
respond(&testResponseWriter, response)
}
}

Loading…
Cancel
Save