github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/pkg/sql/rowexec/noop_test.go (about)

     1  // Copyright 2018 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 rowexec
    12  
    13  import (
    14  	"context"
    15  	"fmt"
    16  	"testing"
    17  
    18  	"github.com/cockroachdb/cockroach/pkg/settings/cluster"
    19  	"github.com/cockroachdb/cockroach/pkg/sql/execinfra"
    20  	"github.com/cockroachdb/cockroach/pkg/sql/execinfrapb"
    21  	"github.com/cockroachdb/cockroach/pkg/sql/sem/tree"
    22  	"github.com/cockroachdb/cockroach/pkg/sql/sqlbase"
    23  	"github.com/cockroachdb/cockroach/pkg/sql/types"
    24  )
    25  
    26  func BenchmarkNoop(b *testing.B) {
    27  	const numRows = 1 << 16
    28  
    29  	ctx := context.Background()
    30  	st := cluster.MakeTestingClusterSettings()
    31  	evalCtx := tree.MakeTestingEvalContext(st)
    32  	defer evalCtx.Stop(ctx)
    33  
    34  	flowCtx := &execinfra.FlowCtx{
    35  		Cfg:     &execinfra.ServerConfig{Settings: st},
    36  		EvalCtx: &evalCtx,
    37  	}
    38  	post := &execinfrapb.PostProcessSpec{}
    39  	disposer := &rowDisposer{}
    40  	for _, numCols := range []int{1, 1 << 1, 1 << 2, 1 << 4, 1 << 8} {
    41  		b.Run(fmt.Sprintf("cols=%d", numCols), func(b *testing.B) {
    42  			cols := make([]*types.T, numCols)
    43  			for i := range cols {
    44  				cols[i] = types.Int
    45  			}
    46  			input := execinfra.NewRepeatableRowSource(cols, sqlbase.MakeIntRows(numRows, numCols))
    47  
    48  			b.SetBytes(int64(8 * numRows * numCols))
    49  			b.ResetTimer()
    50  			for i := 0; i < b.N; i++ {
    51  				d, err := newNoopProcessor(flowCtx, 0 /* processorID */, input, post, disposer)
    52  				if err != nil {
    53  					b.Fatal(err)
    54  				}
    55  				d.Run(context.Background())
    56  				input.Reset()
    57  			}
    58  		})
    59  	}
    60  }