github.com/whtcorpsinc/MilevaDB-Prod@v0.0.0-20211104133533-f57f4be3b597/dbs/memristed/memex/aggregation/bench_test.go (about)

     1  // Copyright 2020 WHTCORPS INC, Inc.
     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  // See the License for the specific language governing permissions and
    12  // limitations under the License.
    13  
    14  package aggregation
    15  
    16  import (
    17  	"testing"
    18  
    19  	"github.com/whtcorpsinc/BerolinaSQL/ast"
    20  	"github.com/whtcorpsinc/BerolinaSQL/allegrosql"
    21  	"github.com/whtcorpsinc/milevadb/memex"
    22  	"github.com/whtcorpsinc/milevadb/types"
    23  	"github.com/whtcorpsinc/milevadb/soliton/mock"
    24  )
    25  
    26  func BenchmarkCreateContext(b *testing.B) {
    27  	defCaus := &memex.DeferredCauset{
    28  		Index:   0,
    29  		RetType: types.NewFieldType(allegrosql.TypeLonglong),
    30  	}
    31  	ctx := mock.NewContext()
    32  	desc, err := NewAggFuncDesc(ctx, ast.AggFuncAvg, []memex.Expression{defCaus}, false)
    33  	if err != nil {
    34  		b.Fatal(err)
    35  	}
    36  	fun := desc.GetAggFunc(ctx)
    37  	b.StartTimer()
    38  	for i := 0; i < b.N; i++ {
    39  		fun.CreateContext(ctx.GetStochastikVars().StmtCtx)
    40  	}
    41  	b.ReportAllocs()
    42  }
    43  
    44  func BenchmarkResetContext(b *testing.B) {
    45  	defCaus := &memex.DeferredCauset{
    46  		Index:   0,
    47  		RetType: types.NewFieldType(allegrosql.TypeLonglong),
    48  	}
    49  	ctx := mock.NewContext()
    50  	desc, err := NewAggFuncDesc(ctx, ast.AggFuncAvg, []memex.Expression{defCaus}, false)
    51  	if err != nil {
    52  		b.Fatal(err)
    53  	}
    54  	fun := desc.GetAggFunc(ctx)
    55  	evalCtx := fun.CreateContext(ctx.GetStochastikVars().StmtCtx)
    56  	b.StartTimer()
    57  	for i := 0; i < b.N; i++ {
    58  		fun.ResetContext(ctx.GetStochastikVars().StmtCtx, evalCtx)
    59  	}
    60  	b.ReportAllocs()
    61  }
    62  
    63  func BenchmarkCreateDistinctContext(b *testing.B) {
    64  	defCaus := &memex.DeferredCauset{
    65  		Index:   0,
    66  		RetType: types.NewFieldType(allegrosql.TypeLonglong),
    67  	}
    68  	ctx := mock.NewContext()
    69  	desc, err := NewAggFuncDesc(ctx, ast.AggFuncAvg, []memex.Expression{defCaus}, true)
    70  	if err != nil {
    71  		b.Fatal(err)
    72  	}
    73  	fun := desc.GetAggFunc(ctx)
    74  	b.StartTimer()
    75  	for i := 0; i < b.N; i++ {
    76  		fun.CreateContext(ctx.GetStochastikVars().StmtCtx)
    77  	}
    78  	b.ReportAllocs()
    79  }
    80  
    81  func BenchmarkResetDistinctContext(b *testing.B) {
    82  	defCaus := &memex.DeferredCauset{
    83  		Index:   0,
    84  		RetType: types.NewFieldType(allegrosql.TypeLonglong),
    85  	}
    86  	ctx := mock.NewContext()
    87  	desc, err := NewAggFuncDesc(ctx, ast.AggFuncAvg, []memex.Expression{defCaus}, true)
    88  	if err != nil {
    89  		b.Fatal(err)
    90  	}
    91  	fun := desc.GetAggFunc(ctx)
    92  	evalCtx := fun.CreateContext(ctx.GetStochastikVars().StmtCtx)
    93  	b.StartTimer()
    94  	for i := 0; i < b.N; i++ {
    95  		fun.ResetContext(ctx.GetStochastikVars().StmtCtx, evalCtx)
    96  	}
    97  	b.ReportAllocs()
    98  }