2021-01-17 21:46:25 +08:00
|
|
|
// Copyright GoFrame Author(https://goframe.org). All Rights Reserved.
|
2018-05-28 13:58:59 +08:00
|
|
|
//
|
|
|
|
|
// 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,
|
2019-02-02 16:18:25 +08:00
|
|
|
// You can obtain one at https://github.com/gogf/gf.
|
2018-05-28 13:58:59 +08:00
|
|
|
|
|
|
|
|
// go test *.go -bench=".*"
|
|
|
|
|
|
2019-02-19 11:19:23 +08:00
|
|
|
package gregex_test
|
2018-05-28 13:58:59 +08:00
|
|
|
|
|
|
|
|
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"
|
2018-05-28 13:58:59 +08:00
|
|
|
)
|
|
|
|
|
|
2019-06-03 16:59:33 +08:00
|
|
|
var pattern = `(\w+).+\-\-\s*(.+)`
|
2022-11-01 20:12:21 +08:00
|
|
|
|
2019-06-19 09:06:52 +08:00
|
|
|
var src = `GF is best! -- John`
|
2018-05-28 13:58:59 +08:00
|
|
|
|
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)
|
|
|
|
|
}
|
2018-05-28 13:58:59 +08:00
|
|
|
}
|
|
|
|
|
|
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)
|
|
|
|
|
}
|
2018-05-28 13:58:59 +08:00
|
|
|
}
|
|
|
|
|
|
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)
|
|
|
|
|
}
|
2018-05-28 13:58:59 +08:00
|
|
|
}
|