github.com/matrixorigin/matrixone@v1.2.0/pkg/vm/engine/tae/tables/functions_test.go (about) 1 // Copyright 2021 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 tables 16 17 import ( 18 "testing" 19 20 "github.com/matrixorigin/matrixone/pkg/container/types" 21 "github.com/matrixorigin/matrixone/pkg/vm/engine/tae/common" 22 "github.com/matrixorigin/matrixone/pkg/vm/engine/tae/containers" 23 ) 24 25 func BenchmarkFunctions(b *testing.B) { 26 vec := containers.MockVector2(types.T_int64.ToType(), 10000, 0) 27 defer vec.Close() 28 vec2 := containers.MakeVector(*vec.GetType(), common.DefaultAllocator) 29 defer vec2.Close() 30 for i := 9999999; i < 9999999+1000; i++ { 31 vec2.Append(int64(i), false) 32 } 33 34 b.Run("old-dedup-int64", func(b *testing.B) { 35 b.ResetTimer() 36 for i := 0; i < b.N; i++ { 37 vec2.Foreach(dedupNABlkClosure(vec, nil, nil, nil), nil) 38 } 39 }) 40 b.Run("new-dedup-int64", func(b *testing.B) { 41 op := containers.MakeForeachVectorOp(vec2.GetType().Oid, dedupNABlkFunctions, vec, nil, nil) 42 b.ResetTimer() 43 for i := 0; i < b.N; i++ { 44 containers.ForeachVectorWindow(vec2, 0, vec2.Length(), op, nil, nil) 45 } 46 }) 47 48 vec3 := containers.MockVector(types.T_decimal128.ToType(), 20000, true, nil) 49 defer vec3.Close() 50 vec4 := vec3.CloneWindow(0, 10000) 51 defer vec4.Close() 52 vec5 := vec3.CloneWindow(11000, 100) 53 defer vec5.Close() 54 b.Run("old-dedup-d128", func(b *testing.B) { 55 b.ResetTimer() 56 for i := 0; i < b.N; i++ { 57 vec5.Foreach(dedupNABlkClosure(vec4, nil, nil, nil), nil) 58 } 59 }) 60 b.Run("new-dedup-d128", func(b *testing.B) { 61 op := containers.MakeForeachVectorOp(vec4.GetType().Oid, dedupNABlkFunctions, vec4, nil, nil) 62 b.ResetTimer() 63 for i := 0; i < b.N; i++ { 64 containers.ForeachVectorWindow(vec5, 0, vec5.Length(), op, nil, nil) 65 } 66 }) 67 68 vec6 := containers.MockVector2(types.T_varchar.ToType(), 12000, 0) 69 defer vec6.Close() 70 vec7 := vec6.CloneWindow(0, 10000) 71 defer vec7.Close() 72 vec8 := vec6.CloneWindow(10500, 10) 73 defer vec8.Close() 74 75 b.Run("old-dedup-chars", func(b *testing.B) { 76 b.ResetTimer() 77 for i := 0; i < b.N; i++ { 78 vec8.Foreach(dedupNABlkClosure(vec7, nil, nil, nil), nil) 79 } 80 }) 81 b.Run("new-dedup-chars", func(b *testing.B) { 82 op := containers.MakeForeachVectorOp(vec7.GetType().Oid, dedupNABlkFunctions, vec7, nil, nil) 83 b.ResetTimer() 84 for i := 0; i < b.N; i++ { 85 containers.ForeachVectorWindow(vec8, 0, vec8.Length(), op, nil, nil) 86 } 87 }) 88 89 b.Run("old-dedup-achars", func(b *testing.B) { 90 b.ResetTimer() 91 for i := 0; i < b.N; i++ { 92 vec8.Foreach(dedupABlkClosureFactory(nil)(vec7, nil, nil, nil), nil) 93 } 94 }) 95 96 b.Run("new-dedup-achars", func(b *testing.B) { 97 op := containers.MakeForeachVectorOp(vec7.GetType().Oid, dedupAlkFunctions, vec7, nil, nil, nil, nil) 98 b.ResetTimer() 99 for i := 0; i < b.N; i++ { 100 containers.ForeachVectorWindow(vec8, 0, vec8.Length(), op, nil, nil) 101 } 102 }) 103 }