|
| 1 | +// Copyright 2018 PingCAP, 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/pingcap/tidb/ast" |
| 20 | + "github.com/pingcap/tidb/expression" |
| 21 | + "github.com/pingcap/tidb/mysql" |
| 22 | + "github.com/pingcap/tidb/types" |
| 23 | + "github.com/pingcap/tidb/util/mock" |
| 24 | +) |
| 25 | + |
| 26 | +func BenchmarkCreateContext(b *testing.B) { |
| 27 | + col := &expression.Column{ |
| 28 | + Index: 0, |
| 29 | + RetType: types.NewFieldType(mysql.TypeLonglong), |
| 30 | + } |
| 31 | + ctx := mock.NewContext() |
| 32 | + fun := NewAggFuncDesc(ctx, ast.AggFuncAvg, []expression.Expression{col}, false).GetAggFunc() |
| 33 | + b.StartTimer() |
| 34 | + for i := 0; i < b.N; i++ { |
| 35 | + fun.CreateContext(ctx.GetSessionVars().StmtCtx) |
| 36 | + } |
| 37 | + b.ReportAllocs() |
| 38 | +} |
| 39 | + |
| 40 | +func BenchmarkResetContext(b *testing.B) { |
| 41 | + col := &expression.Column{ |
| 42 | + Index: 0, |
| 43 | + RetType: types.NewFieldType(mysql.TypeLonglong), |
| 44 | + } |
| 45 | + ctx := mock.NewContext() |
| 46 | + fun := NewAggFuncDesc(ctx, ast.AggFuncAvg, []expression.Expression{col}, false).GetAggFunc() |
| 47 | + evalCtx := fun.CreateContext(ctx.GetSessionVars().StmtCtx) |
| 48 | + b.StartTimer() |
| 49 | + for i := 0; i < b.N; i++ { |
| 50 | + fun.ResetContext(ctx.GetSessionVars().StmtCtx, evalCtx) |
| 51 | + } |
| 52 | + b.ReportAllocs() |
| 53 | +} |
| 54 | + |
| 55 | +func BenchmarkCreateDistinctContext(b *testing.B) { |
| 56 | + col := &expression.Column{ |
| 57 | + Index: 0, |
| 58 | + RetType: types.NewFieldType(mysql.TypeLonglong), |
| 59 | + } |
| 60 | + ctx := mock.NewContext() |
| 61 | + fun := NewAggFuncDesc(ctx, ast.AggFuncAvg, []expression.Expression{col}, true).GetAggFunc() |
| 62 | + b.StartTimer() |
| 63 | + for i := 0; i < b.N; i++ { |
| 64 | + fun.CreateContext(ctx.GetSessionVars().StmtCtx) |
| 65 | + } |
| 66 | + b.ReportAllocs() |
| 67 | +} |
| 68 | + |
| 69 | +func BenchmarkResetDistinctContext(b *testing.B) { |
| 70 | + col := &expression.Column{ |
| 71 | + Index: 0, |
| 72 | + RetType: types.NewFieldType(mysql.TypeLonglong), |
| 73 | + } |
| 74 | + ctx := mock.NewContext() |
| 75 | + fun := NewAggFuncDesc(ctx, ast.AggFuncAvg, []expression.Expression{col}, true).GetAggFunc() |
| 76 | + evalCtx := fun.CreateContext(ctx.GetSessionVars().StmtCtx) |
| 77 | + b.StartTimer() |
| 78 | + for i := 0; i < b.N; i++ { |
| 79 | + fun.ResetContext(ctx.GetSessionVars().StmtCtx, evalCtx) |
| 80 | + } |
| 81 | + b.ReportAllocs() |
| 82 | +} |
0 commit comments