From 85b104bafab9540f9a5f9403c0f2a18be85f4ff5 Mon Sep 17 00:00:00 2001 From: John Date: Mon, 3 Jun 2019 16:59:33 +0800 Subject: [PATCH] update benchmark test cases for gregex --- g/text/gregex/gregex_z_bench_test.go | 58 +++++++++------------------- 1 file changed, 18 insertions(+), 40 deletions(-) diff --git a/g/text/gregex/gregex_z_bench_test.go b/g/text/gregex/gregex_z_bench_test.go index db72f9d28..cd83dc1db 100644 --- a/g/text/gregex/gregex_z_bench_test.go +++ b/g/text/gregex/gregex_z_bench_test.go @@ -10,51 +10,29 @@ package gregex_test import ( "github.com/gogf/gf/g/text/gregex" - "testing" + "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 Benchmark_GF(b *testing.B) { + for i := 0; i < b.N; i++ { + gregex.IsMatchString(pattern, src) + } } -func BenchmarkIsMatch(b *testing.B) { - for i := 0; i < b.N; i++ { - gregex.IsMatch(pattern, []byte(src)) - } +func Benchmark_Compile(b *testing.B) { + var wcdRegexp = regexp.MustCompile(pattern) + for i := 0; i < b.N; i++ { + wcdRegexp.MatchString(src) + } } -func BenchmarkIsMatchString(b *testing.B) { - for i := 0; i < b.N; i++ { - gregex.IsMatchString(pattern, src) - } -} - -func BenchmarkMatchString(b *testing.B) { - for i := 0; i < b.N; i++ { - gregex.MatchString(pattern, src) - } -} - -func BenchmarkMatchAllString(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) - } +func Benchmark_Compile_Actual(b *testing.B) { + for i := 0; i < b.N; i++ { + wcdRegexp := regexp.MustCompile(pattern) + wcdRegexp.MatchString(src) + } }