github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/pkg/sql/covering/bench_test.go (about) 1 // Copyright 2020 The Cockroach Authors. 2 // 3 // Use of this software is governed by the Business Source License 4 // included in the file licenses/BSL.txt. 5 // 6 // As of the Change Date specified in that file, in accordance with 7 // the Business Source License, use of this software will be governed 8 // by the Apache License, Version 2.0, included in the file 9 // licenses/APL.txt. 10 11 package covering 12 13 import ( 14 "encoding/binary" 15 "fmt" 16 "math/rand" 17 "testing" 18 19 "github.com/cockroachdb/cockroach/pkg/util/timeutil" 20 "github.com/stretchr/testify/require" 21 ) 22 23 func BenchmarkOverlapCoveringMerge(b *testing.B) { 24 var benchmark []struct { 25 name string 26 inputs []Covering 27 } 28 rand.Seed(timeutil.Now().Unix()) 29 30 for _, numLayers := range []int{ 31 1, // single backup 32 24, // hourly backups 33 24 * 7, // hourly backups for a week. 34 } { 35 // number of elements per each backup instance 36 for _, elementsPerLayer := range []int{100, 1000, 10000} { 37 var inputs []Covering 38 39 for i := 0; i < numLayers; i++ { 40 var payload int 41 var c Covering 42 step := 1 + rand.Intn(10) 43 44 for j := 0; j < elementsPerLayer; j += step { 45 start := make([]byte, 4) 46 binary.LittleEndian.PutUint32(start, uint32(j)) 47 48 end := make([]byte, 4) 49 binary.LittleEndian.PutUint32(end, uint32(j+step)) 50 51 c = append(c, Range{ 52 Start: start, 53 End: end, 54 Payload: payload, 55 }) 56 payload++ 57 } 58 inputs = append(inputs, c) 59 } 60 61 benchmark = append(benchmark, struct { 62 name string 63 inputs []Covering 64 }{name: fmt.Sprintf("layers=%d,elems=%d", numLayers, elementsPerLayer), inputs: inputs}) 65 } 66 } 67 68 b.ResetTimer() 69 for _, bench := range benchmark { 70 inputs := bench.inputs 71 b.Run(bench.name, func(b *testing.B) { 72 for i := 0; i < b.N; i++ { 73 require.NotEmpty(b, OverlapCoveringMerge(inputs)) 74 } 75 }) 76 } 77 }