MCPcopy
hub / github.com/grafana/tempo / BenchmarkHistogramAggregator_Results

Function BenchmarkHistogramAggregator_Results

pkg/traceql/engine_metrics_test.go:3142–3188  ·  view source on GitHub ↗
(b *testing.B)

Source from the content-addressed store, hash-verified

3140}
3141
3142func BenchmarkHistogramAggregator_Results(b *testing.B) {
3143 // nolint:gosec // G115
3144 req := &tempopb.QueryRangeRequest{
3145 Start: uint64(time.Now().Add(-1 * time.Hour).UnixNano()),
3146 End: uint64(time.Now().UnixNano()),
3147 Step: uint64(15 * time.Second.Nanoseconds()),
3148 Exemplars: 100,
3149 }
3150
3151 benchmarks := []struct {
3152 name string
3153 seriesCount int
3154 samplesCount int
3155 exemplarCount int
3156 quantiles []float64
3157 }{
3158 {"Small_3Quantiles", 6, 10, 5, []float64{0.5, 0.9, 0.99}},
3159 {"Medium_3Quantiles", 10, 100, 20, []float64{0.5, 0.9, 0.99}},
3160 {"Large_3Quantiles", 20, 1000, 100, []float64{0.5, 0.9, 0.99}},
3161 // These test the bucket rescanning optimization specifically
3162 {"Small_5Quantiles", 6, 10, 5, []float64{0.5, 0.75, 0.9, 0.95, 0.99}},
3163 {"Medium_5Quantiles", 10, 100, 20, []float64{0.5, 0.75, 0.9, 0.95, 0.99}},
3164 {"Large_5Quantiles", 20, 1000, 100, []float64{0.5, 0.75, 0.9, 0.95, 0.99}},
3165 // High exemplar density to test caching benefits
3166 {"High_Exemplars", 10, 100, 200, []float64{0.5, 0.9, 0.99}},
3167 }
3168
3169 for _, bm := range benchmarks {
3170 b.Run(bm.name, func(b *testing.B) {
3171 // Generate test data
3172 series := generateTestTimeSeries(bm.seriesCount, bm.samplesCount, bm.exemplarCount, req.Start, req.End)
3173
3174 // Create histogram aggregator
3175 h := NewHistogramAggregator(req, bm.quantiles, req.Exemplars)
3176
3177 // Combine the series (this is setup, not benchmarked)
3178 h.Combine(series)
3179
3180 // Benchmark the Results method
3181 b.ResetTimer()
3182 for i := 0; i < b.N; i++ {
3183 results := h.Results()
3184 _ = results // Prevent optimization
3185 }
3186 })
3187 }
3188}
3189
3190// generateTestTimeSeries creates test time series data for benchmarking
3191// nolint:gosec // G115

Callers

nothing calls this directly

Calls 7

CombineMethod · 0.95
ResultsMethod · 0.95
generateTestTimeSeriesFunction · 0.85
NewHistogramAggregatorFunction · 0.85
AddMethod · 0.65
NowMethod · 0.65
RunMethod · 0.45

Tested by

no test coverage detected