github.com/grafana/pyroscope@v1.18.0/pkg/metastore/compaction/compactor/compaction_queue_bench_test.go (about)

     1  package compactor
     2  
     3  import (
     4  	"strconv"
     5  	"testing"
     6  
     7  	"github.com/grafana/pyroscope/pkg/metastore/compaction"
     8  )
     9  
    10  func BenchmarkCompactionQueue_Push(b *testing.B) {
    11  	const (
    12  		tenants = 1
    13  		levels  = 1
    14  		shards  = 64
    15  	)
    16  
    17  	q := newCompactionQueue(DefaultConfig(), nil)
    18  	keys := make([]compactionKey, levels*tenants*shards)
    19  	for i := range keys {
    20  		keys[i] = compactionKey{
    21  			tenant: strconv.Itoa(i % tenants),
    22  			shard:  uint32(i % shards),
    23  			level:  uint32(i % levels),
    24  		}
    25  	}
    26  
    27  	b.ResetTimer()
    28  	b.ReportAllocs()
    29  
    30  	for i := 0; i < b.N; i++ {
    31  		k := keys[i%len(keys)]
    32  		q.push(compaction.BlockEntry{
    33  			Index:      uint64(i),
    34  			AppendedAt: int64(i),
    35  			ID:         strconv.Itoa(i),
    36  			Tenant:     k.tenant,
    37  			Shard:      k.shard,
    38  			Level:      k.level,
    39  		})
    40  	}
    41  }