miller/pkg/transformers
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
..
utils Export library code in pkg/ (#1391) 2023-09-10 17:15:13 -04:00
aaa_chain_transformer.go Export library code in pkg/ (#1391) 2023-09-10 17:15:13 -04:00
aaa_record_transformer.go Export library code in pkg/ (#1391) 2023-09-10 17:15:13 -04:00
aaa_transformer_table.go Export library code in pkg/ (#1391) 2023-09-10 17:15:13 -04:00
altkv.go Export library code in pkg/ (#1391) 2023-09-10 17:15:13 -04:00
bar.go Export library code in pkg/ (#1391) 2023-09-10 17:15:13 -04:00
bootstrap.go Export library code in pkg/ (#1391) 2023-09-10 17:15:13 -04:00
case.go Export library code in pkg/ (#1391) 2023-09-10 17:15:13 -04:00
cat.go Export library code in pkg/ (#1391) 2023-09-10 17:15:13 -04:00
check.go Export library code in pkg/ (#1391) 2023-09-10 17:15:13 -04:00
clean_whitespace.go Export library code in pkg/ (#1391) 2023-09-10 17:15:13 -04:00
count.go Export library code in pkg/ (#1391) 2023-09-10 17:15:13 -04:00
count_similar.go Export library code in pkg/ (#1391) 2023-09-10 17:15:13 -04:00
cut.go Export library code in pkg/ (#1391) 2023-09-10 17:15:13 -04:00
decimate.go Export library code in pkg/ (#1391) 2023-09-10 17:15:13 -04:00
doc.go Export library code in pkg/ (#1391) 2023-09-10 17:15:13 -04:00
fill_down.go Export library code in pkg/ (#1391) 2023-09-10 17:15:13 -04:00
fill_empty.go Export library code in pkg/ (#1391) 2023-09-10 17:15:13 -04:00
flatten.go Export library code in pkg/ (#1391) 2023-09-10 17:15:13 -04:00
format_values.go Export library code in pkg/ (#1391) 2023-09-10 17:15:13 -04:00
fraction.go Export library code in pkg/ (#1391) 2023-09-10 17:15:13 -04:00
gap.go Export library code in pkg/ (#1391) 2023-09-10 17:15:13 -04:00
grep.go transformers/grep: avoid allocations with (*regexp.Regexp).MatchString (#1416) 2023-10-27 09:15:12 -04:00
group_by.go Export library code in pkg/ (#1391) 2023-09-10 17:15:13 -04:00
group_like.go Export library code in pkg/ (#1391) 2023-09-10 17:15:13 -04:00
gsub.go Export library code in pkg/ (#1391) 2023-09-10 17:15:13 -04:00
having_fields.go Export library code in pkg/ (#1391) 2023-09-10 17:15:13 -04:00
head.go Export library code in pkg/ (#1391) 2023-09-10 17:15:13 -04:00
histogram.go Export library code in pkg/ (#1391) 2023-09-10 17:15:13 -04:00
join.go Export library code in pkg/ (#1391) 2023-09-10 17:15:13 -04:00
json_parse.go Export library code in pkg/ (#1391) 2023-09-10 17:15:13 -04:00
json_stringify.go Export library code in pkg/ (#1391) 2023-09-10 17:15:13 -04:00
label.go Export library code in pkg/ (#1391) 2023-09-10 17:15:13 -04:00
latin1_to_utf8.go Export library code in pkg/ (#1391) 2023-09-10 17:15:13 -04:00
merge_fields.go Export library code in pkg/ (#1391) 2023-09-10 17:15:13 -04:00
most_or_least_frequent.go Export library code in pkg/ (#1391) 2023-09-10 17:15:13 -04:00
nest.go Export library code in pkg/ (#1391) 2023-09-10 17:15:13 -04:00
nothing.go Export library code in pkg/ (#1391) 2023-09-10 17:15:13 -04:00
put_or_filter.go 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
regularize.go Export library code in pkg/ (#1391) 2023-09-10 17:15:13 -04:00
remove_empty_columns.go Export library code in pkg/ (#1391) 2023-09-10 17:15:13 -04:00
rename.go Export library code in pkg/ (#1391) 2023-09-10 17:15:13 -04:00
reorder.go Export library code in pkg/ (#1391) 2023-09-10 17:15:13 -04:00
repeat.go Export library code in pkg/ (#1391) 2023-09-10 17:15:13 -04:00
reshape.go Export library code in pkg/ (#1391) 2023-09-10 17:15:13 -04:00
sample.go Export library code in pkg/ (#1391) 2023-09-10 17:15:13 -04:00
sec2gmt.go Export library code in pkg/ (#1391) 2023-09-10 17:15:13 -04:00
sec2gmtdate.go Export library code in pkg/ (#1391) 2023-09-10 17:15:13 -04:00
seqgen.go Export library code in pkg/ (#1391) 2023-09-10 17:15:13 -04:00
shuffle.go Export library code in pkg/ (#1391) 2023-09-10 17:15:13 -04:00
skip_trivial_records.go Export library code in pkg/ (#1391) 2023-09-10 17:15:13 -04:00
sort.go Export library code in pkg/ (#1391) 2023-09-10 17:15:13 -04:00
sort_within_records.go Export library code in pkg/ (#1391) 2023-09-10 17:15:13 -04:00
split.go Export library code in pkg/ (#1391) 2023-09-10 17:15:13 -04:00
ssub.go Export library code in pkg/ (#1391) 2023-09-10 17:15:13 -04:00
stats1.go Export library code in pkg/ (#1391) 2023-09-10 17:15:13 -04:00
stats2.go Export library code in pkg/ (#1391) 2023-09-10 17:15:13 -04:00
step.go Export library code in pkg/ (#1391) 2023-09-10 17:15:13 -04:00
sub.go Export library code in pkg/ (#1391) 2023-09-10 17:15:13 -04:00
summary.go Export library code in pkg/ (#1391) 2023-09-10 17:15:13 -04:00
tac.go Export library code in pkg/ (#1391) 2023-09-10 17:15:13 -04:00
tail.go Export library code in pkg/ (#1391) 2023-09-10 17:15:13 -04:00
tee.go Export library code in pkg/ (#1391) 2023-09-10 17:15:13 -04:00
template.go Export library code in pkg/ (#1391) 2023-09-10 17:15:13 -04:00
top.go Export library code in pkg/ (#1391) 2023-09-10 17:15:13 -04:00
unflatten.go Export library code in pkg/ (#1391) 2023-09-10 17:15:13 -04:00
uniq.go Export library code in pkg/ (#1391) 2023-09-10 17:15:13 -04:00
unspace.go Export library code in pkg/ (#1391) 2023-09-10 17:15:13 -04:00
unsparsify.go Export library code in pkg/ (#1391) 2023-09-10 17:15:13 -04:00
utf8_to_latin1.go Export library code in pkg/ (#1391) 2023-09-10 17:15:13 -04:00

Logic for transforming input records into output records as requested by the user (sort, filter, etc.).:

  • The IRecordTransformer abstract record-transformer interface datatype, as well as the ChainTransformer Go-channel chaining mechanism for piping one transformer into the next.
  • The transformer lookup table, used for Miller command-line parsing, verb construction, and online help.
  • All the concrete record-transformers such as cat, tac, sort, put, and so on.