github.com/matrixorigin/matrixone@v0.7.0/pkg/vm/engine/disttae/bench_test.go (about)

     1  // Copyright 2022 Matrix Origin
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //      http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package disttae
    16  
    17  import (
    18  	"context"
    19  	"fmt"
    20  	"testing"
    21  
    22  	"github.com/matrixorigin/matrixone/pkg/common/mpool"
    23  	"github.com/matrixorigin/matrixone/pkg/container/batch"
    24  	"github.com/matrixorigin/matrixone/pkg/container/types"
    25  	"github.com/matrixorigin/matrixone/pkg/container/vector"
    26  	"github.com/matrixorigin/matrixone/pkg/testutil"
    27  )
    28  
    29  func BenchmarkPartitionInsert(b *testing.B) {
    30  	for i := 0; i < b.N; i++ {
    31  
    32  		mp := mpool.MustNewZero()
    33  		part := NewPartition(nil)
    34  		ctx := context.Background()
    35  		numRows := 100
    36  		v0 := make([]int64, numRows)
    37  		v1 := make([]string, numRows)
    38  		v2 := make([]types.Rowid, numRows)
    39  		v3 := make([]types.TS, numRows)
    40  		zs := make([]int64, numRows)
    41  		for i := 0; i < len(zs); i++ {
    42  			zs[i] = 1
    43  		}
    44  		vecs := make([]*vector.Vector, 4)
    45  		for i := 0; i < 1000*numRows; i += numRows {
    46  			{
    47  				for j := 0; j < numRows; j++ {
    48  					v0[j] = int64(j + i)
    49  					v1[j] = fmt.Sprintf("%v", j+i)
    50  					x := uint64(i + j)
    51  					copy(v2[j][:], types.EncodeUint64(&x))
    52  					copy(v3[j][:], types.EncodeUint64(&x))
    53  				}
    54  			}
    55  			vecs[0] = testutil.NewVector(1000, types.New(types.T_Rowid, 0, 0, 0), mp, false, v2)
    56  			vecs[1] = testutil.NewVector(1000, types.New(types.T_TS, 0, 0, 0), mp, false, v3)
    57  			vecs[2] = testutil.NewVector(1000, types.New(types.T_int64, 0, 0, 0), mp, false, v0)
    58  			vecs[3] = testutil.NewVector(1000, types.New(types.T_varchar, 0, 0, 0), mp, false, v0)
    59  			bat := testutil.NewBatchWithVectors(vecs, zs)
    60  			bat.Attrs = []string{"0", "1", "2", "3"}
    61  			ebat, _ := batch.BatchToProtoBatch(bat)
    62  			if err := part.Insert(ctx, -1, ebat, false); err != nil {
    63  				panic(err)
    64  			}
    65  			bat.Clean(mp)
    66  		}
    67  
    68  	}
    69  
    70  }