github.com/gogf/gf@v1.16.9/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/gogf/gf. 6 7 // go test *.go -bench=".*" 8 9 package gregex_test 10 11 import ( 12 "regexp" 13 "testing" 14 15 "github.com/gogf/gf/text/gregex" 16 ) 17 18 var pattern = `(\w+).+\-\-\s*(.+)` 19 var src = `GF is best! -- John` 20 21 func Benchmark_GF_IsMatchString(b *testing.B) { 22 for i := 0; i < b.N; i++ { 23 gregex.IsMatchString(pattern, src) 24 } 25 } 26 27 func Benchmark_GF_MatchString(b *testing.B) { 28 for i := 0; i < b.N; i++ { 29 gregex.MatchString(pattern, src) 30 } 31 } 32 33 func Benchmark_Compile(b *testing.B) { 34 var wcdRegexp = regexp.MustCompile(pattern) 35 for i := 0; i < b.N; i++ { 36 wcdRegexp.MatchString(src) 37 } 38 } 39 40 func Benchmark_Compile_Actual(b *testing.B) { 41 for i := 0; i < b.N; i++ { 42 wcdRegexp := regexp.MustCompile(pattern) 43 wcdRegexp.MatchString(src) 44 } 45 }