diff --git a/web/api/v1/api_test.go b/web/api/v1/api_test.go index e4128b1b4575310d7c85bbb39392ef432c9ada7d..df4114e25f2df7452fd74714ac3b28fe04b7df8c 100644 --- a/web/api/v1/api_test.go +++ b/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) + } +}