github.com/wangyougui/gf/v2@v2.6.5/text/gregex/gregex_z_bench_test.go (about) 1 // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. 2 // 3 // This Source Code Form is subject to the terms of the MIT License. 4 // If a copy of the MIT was not distributed with this file, 5 // You can obtain one at https://github.com/wangyougui/gf. 6 7 // go test *.go -bench=".*" 8 9 package gregex_test 10 11 import ( 12 "regexp" 13 "testing" 14 15 "github.com/wangyougui/gf/v2/text/gregex" 16 ) 17 18 var pattern = `(\w+).+\-\-\s*(.+)` 19 20 var src = `GF is best! -- John` 21 22 func Benchmark_GF_IsMatchString(b *testing.B) { 23 for i := 0; i < b.N; i++ { 24 gregex.IsMatchString(pattern, src) 25 } 26 } 27 28 func Benchmark_GF_MatchString(b *testing.B) { 29 for i := 0; i < b.N; i++ { 30 gregex.MatchString(pattern, src) 31 } 32 } 33 34 func Benchmark_Compile(b *testing.B) { 35 var wcdRegexp = regexp.MustCompile(pattern) 36 for i := 0; i < b.N; i++ { 37 wcdRegexp.MatchString(src) 38 } 39 } 40 41 func Benchmark_Compile_Actual(b *testing.B) { 42 for i := 0; i < b.N; i++ { 43 wcdRegexp := regexp.MustCompile(pattern) 44 wcdRegexp.MatchString(src) 45 } 46 }