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