github.com/whtcorpsinc/milevadb-prod@v0.0.0-20211104133533-f57f4be3b597/dbs/memristed/memex/builtin_math_vec_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 memex 15 16 import ( 17 "testing" 18 19 . "github.com/whtcorpsinc/check" 20 "github.com/whtcorpsinc/BerolinaSQL/ast" 21 "github.com/whtcorpsinc/BerolinaSQL/allegrosql" 22 "github.com/whtcorpsinc/milevadb/types" 23 ) 24 25 var vecBuiltinMathCases = map[string][]vecExprBenchCase{ 26 ast.Conv: { 27 { 28 retEvalType: types.ETString, 29 childrenTypes: []types.EvalType{types.ETString, types.ETInt, types.ETInt}, 30 }, 31 }, 32 ast.Sign: { 33 {retEvalType: types.ETInt, childrenTypes: []types.EvalType{types.ETReal}}, 34 }, 35 ast.Log: { 36 {retEvalType: types.ETReal, childrenTypes: []types.EvalType{types.ETReal}}, 37 {retEvalType: types.ETReal, childrenTypes: []types.EvalType{types.ETReal, types.ETReal}, geners: []dataGenerator{nil, nil}}, 38 }, 39 ast.Log10: { 40 {retEvalType: types.ETReal, childrenTypes: []types.EvalType{types.ETReal}}, 41 }, 42 ast.Log2: { 43 {retEvalType: types.ETReal, childrenTypes: []types.EvalType{types.ETReal}}, 44 }, 45 ast.Sqrt: { 46 {retEvalType: types.ETReal, childrenTypes: []types.EvalType{types.ETReal}}, 47 }, 48 ast.Acos: { 49 {retEvalType: types.ETReal, childrenTypes: []types.EvalType{types.ETReal}}, 50 }, 51 ast.Asin: { 52 {retEvalType: types.ETReal, childrenTypes: []types.EvalType{types.ETReal}}, 53 }, 54 ast.Atan: { 55 {retEvalType: types.ETReal, childrenTypes: []types.EvalType{types.ETReal}}, 56 }, 57 ast.Atan2: { 58 {retEvalType: types.ETReal, childrenTypes: []types.EvalType{types.ETReal, types.ETReal}}, 59 }, 60 ast.Cos: { 61 {retEvalType: types.ETReal, childrenTypes: []types.EvalType{types.ETReal}}, 62 }, 63 ast.Exp: { 64 {retEvalType: types.ETReal, childrenTypes: []types.EvalType{types.ETReal}, geners: []dataGenerator{newRangeRealGener(-1, 1, 0.2)}}, 65 }, 66 ast.Degrees: { 67 {retEvalType: types.ETReal, childrenTypes: []types.EvalType{types.ETReal}}, 68 }, 69 ast.Cot: { 70 {retEvalType: types.ETReal, childrenTypes: []types.EvalType{types.ETReal}}, 71 }, 72 ast.Radians: { 73 {retEvalType: types.ETReal, childrenTypes: []types.EvalType{types.ETReal}}, 74 }, 75 ast.Sin: { 76 {retEvalType: types.ETReal, childrenTypes: []types.EvalType{types.ETReal}}, 77 }, 78 ast.Tan: { 79 {retEvalType: types.ETReal, childrenTypes: []types.EvalType{types.ETReal}}, 80 }, 81 ast.Abs: { 82 {retEvalType: types.ETDecimal, childrenTypes: []types.EvalType{types.ETDecimal}}, 83 {retEvalType: types.ETReal, childrenTypes: []types.EvalType{types.ETReal}}, 84 {retEvalType: types.ETInt, childrenTypes: []types.EvalType{types.ETInt}}, 85 {retEvalType: types.ETInt, childrenTypes: []types.EvalType{types.ETInt}, childrenFieldTypes: []*types.FieldType{{Tp: allegrosql.TypeInt24, Flag: allegrosql.UnsignedFlag}}}, 86 }, 87 ast.Round: { 88 {retEvalType: types.ETReal, childrenTypes: []types.EvalType{types.ETReal}}, 89 {retEvalType: types.ETReal, childrenTypes: []types.EvalType{types.ETReal, types.ETInt}, geners: []dataGenerator{nil, newRangeInt64Gener(-100, 100)}}, 90 {retEvalType: types.ETDecimal, childrenTypes: []types.EvalType{types.ETDecimal}}, 91 {retEvalType: types.ETDecimal, childrenTypes: []types.EvalType{types.ETDecimal, types.ETInt}}, 92 {retEvalType: types.ETInt, childrenTypes: []types.EvalType{types.ETInt}}, 93 {retEvalType: types.ETInt, childrenTypes: []types.EvalType{types.ETInt, types.ETInt}, geners: []dataGenerator{nil, newRangeInt64Gener(-100, 100)}}, 94 }, 95 ast.Pow: { 96 {retEvalType: types.ETReal, childrenTypes: []types.EvalType{types.ETReal, types.ETReal}, geners: []dataGenerator{newRangeRealGener(0, 10, 0.5), newRangeRealGener(0, 100, 0.5)}}, 97 }, 98 ast.Floor: { 99 {retEvalType: types.ETReal, childrenTypes: []types.EvalType{types.ETReal}, geners: nil}, 100 {retEvalType: types.ETInt, childrenTypes: []types.EvalType{types.ETInt}, childrenFieldTypes: []*types.FieldType{{Tp: allegrosql.TypeInt24}}, geners: nil}, 101 {retEvalType: types.ETInt, childrenTypes: []types.EvalType{types.ETDecimal}, geners: nil}, 102 {retEvalType: types.ETDecimal, childrenTypes: []types.EvalType{types.ETInt}, geners: nil}, 103 {retEvalType: types.ETDecimal, childrenTypes: []types.EvalType{types.ETInt}, childrenFieldTypes: []*types.FieldType{{Tp: allegrosql.TypeLonglong, Flag: allegrosql.UnsignedFlag}}, geners: nil}, 104 {retEvalType: types.ETDecimal, childrenTypes: []types.EvalType{types.ETDecimal}, childrenFieldTypes: []*types.FieldType{{Tp: allegrosql.TypeNewDecimal, Flen: 32, Decimal: 2}}, geners: nil}, 105 }, 106 ast.Ceil: { 107 {retEvalType: types.ETReal, childrenTypes: []types.EvalType{types.ETReal}, geners: nil}, 108 {retEvalType: types.ETInt, childrenTypes: []types.EvalType{types.ETInt}, childrenFieldTypes: []*types.FieldType{{Tp: allegrosql.TypeInt24}}, geners: nil}, 109 {retEvalType: types.ETInt, childrenTypes: []types.EvalType{types.ETDecimal}, geners: nil}, 110 {retEvalType: types.ETDecimal, childrenTypes: []types.EvalType{types.ETInt}, geners: nil}, 111 {retEvalType: types.ETDecimal, childrenTypes: []types.EvalType{types.ETDecimal}, childrenFieldTypes: []*types.FieldType{{Tp: allegrosql.TypeNewDecimal, Flen: 32, Decimal: 2}}, geners: nil}, 112 }, 113 ast.PI: { 114 {retEvalType: types.ETReal}, 115 }, 116 ast.Truncate: { 117 {retEvalType: types.ETReal, childrenTypes: []types.EvalType{types.ETReal, types.ETInt}, geners: []dataGenerator{nil, newRangeInt64Gener(-10, 10)}}, 118 {retEvalType: types.ETInt, childrenTypes: []types.EvalType{types.ETInt, types.ETInt}, geners: []dataGenerator{nil, newRangeInt64Gener(-10, 10)}}, 119 {retEvalType: types.ETInt, childrenTypes: []types.EvalType{types.ETInt, types.ETInt}, childrenFieldTypes: []*types.FieldType{{Tp: allegrosql.TypeInt24, Flag: allegrosql.UnsignedFlag}}, geners: []dataGenerator{nil, newRangeInt64Gener(-10, 10)}}, 120 {retEvalType: types.ETDecimal, childrenTypes: []types.EvalType{types.ETDecimal, types.ETInt}}, 121 }, 122 ast.Rand: { 123 {retEvalType: types.ETReal, childrenTypes: []types.EvalType{types.ETInt}, geners: []dataGenerator{newDefaultGener(0, types.ETInt)}}, 124 }, 125 ast.CRC32: { 126 {retEvalType: types.ETInt, childrenTypes: []types.EvalType{types.ETString}}, 127 }, 128 } 129 130 var vecBuiltinMathCases1 = map[string][]vecExprBenchCase{ 131 ast.Rand: { 132 {retEvalType: types.ETReal}, 133 }, 134 } 135 136 func (s *testEvaluatorSuite) TestVectorizedBuiltinMathEvalOneVec(c *C) { 137 testVectorizedEvalOneVec(c, vecBuiltinMathCases) 138 } 139 140 func (s *testEvaluatorSuite) TestVectorizedBuiltinMathFunc(c *C) { 141 testVectorizedBuiltinFunc(c, vecBuiltinMathCases) 142 } 143 144 func (s *testEvaluatorSuite) TestVectorizedBuiltinMathFuncForRand(c *C) { 145 testVectorizedBuiltinFuncForRand(c, vecBuiltinMathCases1) 146 } 147 148 func BenchmarkVectorizedBuiltinMathEvalOneVec(b *testing.B) { 149 benchmarkVectorizedEvalOneVec(b, vecBuiltinMathCases) 150 } 151 152 func BenchmarkVectorizedBuiltinMathFunc(b *testing.B) { 153 benchmarkVectorizedBuiltinFunc(b, vecBuiltinMathCases) 154 }