miller/pkg/lib
Eng Zer Jun 3966a6a0a1
lib/regex: use string version of regexp methods to reduce allocs (#1614)
Both `(*Regexp).Match` and `(*Regexp).FindAllSubmatchIndex` have
string-based equivalents: `(*Regexp).MatchString` and
`(*Regexp).FindAllStringSubmatchIndex`. We should use the string version
to avoid unnecessary `[]byte` conversions.

Benchmark:

var regex = regexp.MustCompile("foo.*")

func BenchmarkMatch(b *testing.B) {
	for i := 0; i < b.N; i++ {
		if match := regex.Match([]byte("foo bar baz")); !match {
			b.Fail()
		}
	}
}

func BenchmarkMatchString(b *testing.B) {
	for i := 0; i < b.N; i++ {
		if match := regex.MatchString("foo bar baz"); !match {
			b.Fail()
		}
	}
}

func BenchmarkFindAllSubmatchIndex(b *testing.B) {
	for i := 0; i < b.N; i++ {
		if match := regex.FindAllSubmatchIndex([]byte("foo bar baz"), -1); len(match) == 0 {
			b.Fail()
		}
	}
}

func BenchmarkFindAllStringSubmatchIndex(b *testing.B) {
	for i := 0; i < b.N; i++ {
		if match := regex.FindAllStringSubmatchIndex("foo bar baz", -1); len(match) == 0 {
			b.Fail()
		}
	}
}

goos: linux
goarch: amd64
pkg: github.com/johnkerl/miller/pkg/lib
cpu: AMD Ryzen 7 PRO 4750U with Radeon Graphics
BenchmarkMatch-16                         	 2198350	       517.5 ns/op	      16 B/op	       1 allocs/op
BenchmarkMatchString-16                   	 3143605	       371.5 ns/op	       0 B/op	       0 allocs/op
BenchmarkFindAllSubmatchIndex-16          	  921711	      1199 ns/op	     273 B/op	       3 allocs/op
BenchmarkFindAllStringSubmatchIndex-16    	 1212321	       981.0 ns/op	     257 B/op	       2 allocs/op
PASS
coverage: 0.0% of statements
ok  	github.com/johnkerl/miller/pkg/lib	6.576s

Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
2024-08-09 13:09:53 -04:00
..
doc.go Export library code in pkg/ (#1391) 2023-09-10 17:15:13 -04:00
docurl.go Export library code in pkg/ (#1391) 2023-09-10 17:15:13 -04:00
file_readers.go Export library code in pkg/ (#1391) 2023-09-10 17:15:13 -04:00
getoptify.go Export library code in pkg/ (#1391) 2023-09-10 17:15:13 -04:00
halfpipe.go Export library code in pkg/ (#1391) 2023-09-10 17:15:13 -04:00
latin1.go Export library code in pkg/ (#1391) 2023-09-10 17:15:13 -04:00
latin1_test.go Export library code in pkg/ (#1391) 2023-09-10 17:15:13 -04:00
logger.go Export library code in pkg/ (#1391) 2023-09-10 17:15:13 -04:00
mlrmath.go Export library code in pkg/ (#1391) 2023-09-10 17:15:13 -04:00
ordered_map.go Implement mlr uniq -x (#1457) 2023-12-23 16:20:11 -05:00
paragraph.go Export library code in pkg/ (#1391) 2023-09-10 17:15:13 -04:00
rand.go Export library code in pkg/ (#1391) 2023-09-10 17:15:13 -04:00
readfiles.go Replace deprecated io/ioutil functions (#1452) 2023-12-20 09:44:02 -05:00
README.md Export library code in pkg/ (#1391) 2023-09-10 17:15:13 -04:00
regex.go lib/regex: use string version of regexp methods to reduce allocs (#1614) 2024-08-09 13:09:53 -04:00
regex_test.go Rename internal regex functions (#1446) 2023-12-17 12:46:28 -05:00
stats.go Export library code in pkg/ (#1391) 2023-09-10 17:15:13 -04:00
time.go Export library code in pkg/ (#1391) 2023-09-10 17:15:13 -04:00
time_test.go Export library code in pkg/ (#1391) 2023-09-10 17:15:13 -04:00
tsv_codec.go Export library code in pkg/ (#1391) 2023-09-10 17:15:13 -04:00
tsv_codec_test.go Export library code in pkg/ (#1391) 2023-09-10 17:15:13 -04:00
unbackslash.go Export library code in pkg/ (#1391) 2023-09-10 17:15:13 -04:00
unbackslash_test.go Export library code in pkg/ (#1391) 2023-09-10 17:15:13 -04:00
util.go Replace deprecated io/ioutil functions (#1452) 2023-12-20 09:44:02 -05:00

These are basic library routines for Miller.