miller/pkg
Eng Zer Jun 4b34f80f6a
transformers/grep: avoid allocations with (*regexp.Regexp).MatchString (#1416)
We should use `(*regexp.Regexp).MatchString` instead of
`(*regexp.Regexp).Match([]byte(...))` when matching string to avoid
unnecessary `[]byte` conversions and reduce allocations.

Example benchmark:

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

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

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

goos: linux
goarch: amd64
pkg: github.com/johnkerl/miller/pkg/transformers
cpu: AMD Ryzen 7 PRO 4750U with Radeon Graphics
BenchmarkMatch-16          	 5700908	       210.3 ns/op	      16 B/op	       1 allocs/op
BenchmarkMatchString-16    	 8006731	       156.4 ns/op	       0 B/op	       0 allocs/op
PASS
ok  	github.com/johnkerl/miller/pkg/transformers	2.857s

Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
2023-10-27 09:15:12 -04:00
..
auxents Export library code in pkg/ (#1391) 2023-09-10 17:15:13 -04:00
bifs Export library code in pkg/ (#1391) 2023-09-10 17:15:13 -04:00
cli Export library code in pkg/ (#1391) 2023-09-10 17:15:13 -04:00
climain Export library code in pkg/ (#1391) 2023-09-10 17:15:13 -04:00
colorizer Export library code in pkg/ (#1391) 2023-09-10 17:15:13 -04:00
dsl Export library code in pkg/ (#1391) 2023-09-10 17:15:13 -04:00
entrypoint Export library code in pkg/ (#1391) 2023-09-10 17:15:13 -04:00
go-csv Export library code in pkg/ (#1391) 2023-09-10 17:15:13 -04:00
input Export library code in pkg/ (#1391) 2023-09-10 17:15:13 -04:00
lib Export library code in pkg/ (#1391) 2023-09-10 17:15:13 -04:00
mlrval Include null in any typemask (#1395) 2023-09-11 17:15:37 -04:00
output Export library code in pkg/ (#1391) 2023-09-10 17:15:13 -04:00
parsing Export library code in pkg/ (#1391) 2023-09-10 17:15:13 -04:00
pbnjay-strptime Export library code in pkg/ (#1391) 2023-09-10 17:15:13 -04:00
platform Export library code in pkg/ (#1391) 2023-09-10 17:15:13 -04:00
runtime Export library code in pkg/ (#1391) 2023-09-10 17:15:13 -04:00
scan Export library code in pkg/ (#1391) 2023-09-10 17:15:13 -04:00
stream Export library code in pkg/ (#1391) 2023-09-10 17:15:13 -04:00
terminals Export library code in pkg/ (#1391) 2023-09-10 17:15:13 -04:00
transformers transformers/grep: avoid allocations with (*regexp.Regexp).MatchString (#1416) 2023-10-27 09:15:12 -04:00
types Export library code in pkg/ (#1391) 2023-09-10 17:15:13 -04:00
version Export library code in pkg/ (#1391) 2023-09-10 17:15:13 -04:00
README.md Export library code in pkg/ (#1391) 2023-09-10 17:15:13 -04:00

Please see ../../README-dev.md for an overview; please see each subdirectory for details about it.