<commit_before>// Copyright 2017-2018 gf Author(https://github.com/gogf/gf). All Rights Reserved.
//
// 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,
// You can obtain one at https://github.com/gogf/gf.

// go test *.go -bench=".*"

package gregex_test

import (
    "github.com/gogf/gf/g/text/gregex"
    "testing"
)

var pattern = `(.+):(\d+)`
var src     = "johng.cn:80"
var replace = "johng.cn"

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) {
    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)
    }
}<commit_msg>update benchmark test cases for gregex<commit_after>// Copyright 2017-2018 gf Author(https://github.com/gogf/gf). All Rights Reserved.
//
// 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,
// You can obtain one at https://github.com/gogf/gf.

// go test *.go -bench=".*"

package gregex_test

import (
    "github.com/gogf/gf/g/text/gregex"
	"regexp"
	"testing"
)

var pattern = `(\w+).+\-\-\s*(.+)`
var src     = `GF is best! -- John`

func Benchmark_GF(b *testing.B) {
	for i := 0; i < b.N; i++ {
		gregex.IsMatchString(pattern, src)
	}
}

func Benchmark_Compile(b *testing.B) {
	var wcdRegexp = regexp.MustCompile(pattern)
	for i := 0; i < b.N; i++ {
		wcdRegexp.MatchString(src)
	}
}

func Benchmark_Compile_Actual(b *testing.B) {
	for i := 0; i < b.N; i++ {
		wcdRegexp := regexp.MustCompile(pattern)
		wcdRegexp.MatchString(src)
	}
}
{'fraction_non_alphanumeric': 0.16456247279059644, 'fraction_numerical': 0.012189812799303439, 'mean_word_length': 2.83, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 3, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7540559', 'n_tokens_mistral': 933, 'n_tokens_neox': 877, 'n_words': 234}