Files
gf/text/gregex/gregex_z_bench_test.go

47 lines
979 B
Go
Raw Permalink Normal View History

2021-01-17 21:46:25 +08:00
// Copyright GoFrame Author(https://goframe.org). All Rights Reserved.
//
// This Source Code Form is subject to the terms of the MIT License.
// If a copy of the MIT was not distributed with this file,
// You can obtain one at https://github.com/gogf/gf.
// go test *.go -bench=".*"
2019-02-19 11:19:23 +08:00
package gregex_test
import (
2019-06-03 16:59:33 +08:00
"regexp"
"testing"
2019-06-21 22:23:07 +08:00
2021-10-11 21:41:56 +08:00
"github.com/gogf/gf/v2/text/gregex"
)
2019-06-03 16:59:33 +08:00
var pattern = `(\w+).+\-\-\s*(.+)`
2019-06-19 09:06:52 +08:00
var src = `GF is best! -- John`
2020-03-28 00:37:23 +08:00
func Benchmark_GF_IsMatchString(b *testing.B) {
2019-06-03 16:59:33 +08:00
for i := 0; i < b.N; i++ {
gregex.IsMatchString(pattern, src)
}
}
2020-03-28 00:37:23 +08:00
func Benchmark_GF_MatchString(b *testing.B) {
for i := 0; i < b.N; i++ {
gregex.MatchString(pattern, src)
}
}
2019-06-03 16:59:33 +08:00
func Benchmark_Compile(b *testing.B) {
var wcdRegexp = regexp.MustCompile(pattern)
for i := 0; i < b.N; i++ {
wcdRegexp.MatchString(src)
}
}
2019-06-03 16:59:33 +08:00
func Benchmark_Compile_Actual(b *testing.B) {
for i := 0; i < b.N; i++ {
wcdRegexp := regexp.MustCompile(pattern)
wcdRegexp.MatchString(src)
}
}