From 9dfdc3eb3668971523d7d2f24f87f5b1333b545a Mon Sep 17 00:00:00 2001 From: Bryan Boreham Date: Wed, 18 Aug 2021 10:27:21 +0100 Subject: [PATCH] Speed up BenchmarkPostings_Stats (#9213) The previous code re-used series IDs 1-1000 many times over, so a lot of time was spent ensuring the lists of series were in ascending order. The intended use of `MemPostings.Add()` is that all series IDs are unique, and changing the benchmark to do this lets it finish ten times faster. (It doesn't affect the benchmark result, just the setup code) Signed-off-by: Bryan Boreham --- tsdb/index/postings_test.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tsdb/index/postings_test.go b/tsdb/index/postings_test.go index efb00efe9..bbf5332a5 100644 --- a/tsdb/index/postings_test.go +++ b/tsdb/index/postings_test.go @@ -818,10 +818,13 @@ func TestWithoutPostings(t *testing.T) { func BenchmarkPostings_Stats(b *testing.B) { p := NewMemPostings() + var seriesID uint64 + createPostingsLabelValues := func(name, valuePrefix string, count int) { for n := 1; n < count; n++ { value := fmt.Sprintf("%s-%d", valuePrefix, n) - p.Add(uint64(n), labels.FromStrings(name, value)) + p.Add(seriesID, labels.FromStrings(name, value)) + seriesID++ } }