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 (
"github.com/gogf/gf/g/text/gregex"
"regexp"
"testing"
)
var pattern = `(.+):(\d+)`
var src = "johng.cn:80"
var replace = "johng.cn"
var pattern = `(\w+).+\-\-\s*(.+)`
var src = `GF is best! -- John`
func BenchmarkValidate(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) {
func Benchmark_GF(b *testing.B) {
for i := 0; i < b.N; i++ {
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++ {
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++ {
gregex.MatchAllString(pattern, 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)
wcdRegexp := regexp.MustCompile(pattern)
wcdRegexp.MatchString(src)
}
}