mirror of
https://github.com/TeaOSLab/EdgeNode.git
synced 2025-11-11 22:00:25 +08:00
优化代码
This commit is contained in:
@@ -136,6 +136,10 @@ func (this *Regexp) Match(s []byte) bool {
|
||||
return this.rawRegexp.Match(s)
|
||||
}
|
||||
|
||||
func (this *Regexp) FindStringSubmatch(s string) []string {
|
||||
return this.rawRegexp.FindStringSubmatch(s)
|
||||
}
|
||||
|
||||
// ParseKeywords 提取表达式中的关键词
|
||||
func (this *Regexp) ParseKeywords(exp string) (keywords []string) {
|
||||
if len(exp) == 0 {
|
||||
|
||||
@@ -125,11 +125,36 @@ func BenchmarkRegexp_MatchString2(b *testing.B) {
|
||||
func BenchmarkRegexp_MatchString_CaseSensitive(b *testing.B) {
|
||||
var r = re.MustCompile("(abc|def|ghi)")
|
||||
b.Log("keywords:", r.Keywords())
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
r.MatchString("Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.110 Safari/537.36")
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkRegexp_MatchString_CaseSensitive2(b *testing.B) {
|
||||
var r = regexp.MustCompile("(abc|def|ghi)")
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
r.MatchString("Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.110 Safari/537.36")
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkRegexp_MatchString_VS_FindSubString1(b *testing.B) {
|
||||
var r = re.MustCompile("(?i)(chrome)")
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
_ = r.Raw().MatchString("Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.110 Safari/537.36")
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkRegexp_MatchString_VS_FindSubString2(b *testing.B) {
|
||||
var r = re.MustCompile("(?i)(chrome)")
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
_ = r.Raw().FindStringSubmatch("Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.110 Safari/537.36")
|
||||
}
|
||||
}
|
||||
|
||||
func testCompareStrings(s1 []string, s2 []string) bool {
|
||||
if len(s1) != len(s2) {
|
||||
return false
|
||||
|
||||
Reference in New Issue
Block a user