vitess.io/vitess@v0.16.2/go/vt/sqlparser/walker_test.go (about) 1 /* 2 Copyright 2021 The Vitess Authors. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package sqlparser 18 19 import ( 20 "fmt" 21 "testing" 22 23 "github.com/stretchr/testify/require" 24 ) 25 26 func BenchmarkWalkLargeExpression(b *testing.B) { 27 for i := 0; i < 10; i++ { 28 b.Run(fmt.Sprintf("%d", i), func(b *testing.B) { 29 exp := newGenerator(int64(i*100), 5).expression() 30 count := 0 31 for i := 0; i < b.N; i++ { 32 err := Walk(func(node SQLNode) (kontinue bool, err error) { 33 count++ 34 return true, nil 35 }, exp) 36 require.NoError(b, err) 37 } 38 }) 39 } 40 } 41 42 func BenchmarkRewriteLargeExpression(b *testing.B) { 43 for i := 1; i < 7; i++ { 44 b.Run(fmt.Sprintf("%d", i), func(b *testing.B) { 45 exp := newGenerator(int64(i*100), i).expression() 46 count := 0 47 for i := 0; i < b.N; i++ { 48 _ = Rewrite(exp, func(_ *Cursor) bool { 49 count++ 50 return true 51 }, func(_ *Cursor) bool { 52 count-- 53 return true 54 }) 55 } 56 }) 57 } 58 }