update benchmark test cases for gregex

This commit is contained in:
John 2019-06-03 16:59:33 +08:00
parent e4f9e1000d
commit 85b104bafa

View File

@ -10,51 +10,29 @@ package gregex_test
import ( import (
"github.com/gogf/gf/g/text/gregex" "github.com/gogf/gf/g/text/gregex"
"regexp"
"testing" "testing"
) )
var pattern = `(.+):(\d+)` var pattern = `(\w+).+\-\-\s*(.+)`
var src = "johng.cn:80" var src = `GF is best! -- John`
var replace = "johng.cn"
func BenchmarkValidate(b *testing.B) { func Benchmark_GF(b *testing.B) {
for i := 0; i < b.N; i++ {
gregex.Validate(pattern)
}
}
func BenchmarkIsMatch(b *testing.B) {
for i := 0; i < b.N; i++ {
gregex.IsMatch(pattern, []byte(src))
}
}
func BenchmarkIsMatchString(b *testing.B) {
for i := 0; i < b.N; i++ { for i := 0; i < b.N; i++ {
gregex.IsMatchString(pattern, src) gregex.IsMatchString(pattern, src)
} }
} }
func BenchmarkMatchString(b *testing.B) { func Benchmark_Compile(b *testing.B) {
var wcdRegexp = regexp.MustCompile(pattern)
for i := 0; i < b.N; i++ { for i := 0; i < b.N; i++ {
gregex.MatchString(pattern, src) wcdRegexp.MatchString(src)
} }
} }
func BenchmarkMatchAllString(b *testing.B) { func Benchmark_Compile_Actual(b *testing.B) {
for i := 0; i < b.N; i++ { for i := 0; i < b.N; i++ {
gregex.MatchAllString(pattern, src) wcdRegexp := regexp.MustCompile(pattern)
} wcdRegexp.MatchString(src)
}
func BenchmarkReplace(b *testing.B) {
for i := 0; i < b.N; i++ {
gregex.Replace(pattern, []byte(replace), []byte(src))
}
}
func BenchmarkReplaceString(b *testing.B) {
for i := 0; i < b.N; i++ {
gregex.ReplaceString(pattern, replace, src)
} }
} }